Commit 7572315e authored by Olivier Bertrand's avatar Olivier Bertrand

- New handling of default file name:

  Not added as an option but handled when the table is used.
  An empty file is created in the database directory if not exists.

modified:
  storage/connect/ha_connect.cc
  storage/connect/mycat.cc
  storage/connect/tabdos.cpp
  storage/connect/tabmul.cpp
  storage/connect/tabsys.cpp
  storage/connect/tabxml.cpp
parent a2ca6856
...@@ -126,6 +126,7 @@ ...@@ -126,6 +126,7 @@
#include "tabcol.h" #include "tabcol.h"
#include "xindex.h" #include "xindex.h"
#if defined(WIN32) #if defined(WIN32)
#include <io.h>
#include "tabwmi.h" #include "tabwmi.h"
#endif // WIN32 #endif // WIN32
#include "connect.h" #include "connect.h"
...@@ -3388,7 +3389,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3388,7 +3389,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
MEM_ROOT *mem= thd->mem_root; MEM_ROOT *mem= thd->mem_root;
CHARSET_INFO *cs; CHARSET_INFO *cs;
Alter_info *alter_info= (Alter_info*)alt_info; Alter_info *alter_info= (Alter_info*)alt_info;
engine_option_value *pov, *start= create_info->option_list, *end= NULL; engine_option_value *pov, **start= &create_info->option_list, *end= NULL;
PQRYRES qrp; PQRYRES qrp;
PCOLRES crp; PCOLRES crp;
PGLOBAL g= GetPlug(thd); PGLOBAL g= GetPlug(thd);
...@@ -3400,7 +3401,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3400,7 +3401,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
user= NULL; user= NULL;
// Get the useful create options // Get the useful create options
for (pov= start; pov; pov= pov->next) { for (pov= *start; pov; pov= pov->next) {
if (!stricmp(pov->name.str, "table_type")) { if (!stricmp(pov->name.str, "table_type")) {
typn= pov->value.str; typn= pov->value.str;
ttp= GetTypeID(typn); ttp= GetTypeID(typn);
...@@ -3447,15 +3448,13 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3447,15 +3448,13 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
// Check table type // Check table type
if (ttp == TAB_UNDEF || ttp == TAB_NIY) { if (ttp == TAB_UNDEF || ttp == TAB_NIY) {
sprintf(g->Message, "Unknown Table_type '%s'", typn); strcpy(g->Message, "No table_type. Was set to DOS");
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
strcpy(g->Message, "Using Table_type DOS");
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
ttp= TAB_DOS; ttp= TAB_DOS;
typn= "DOS"; typn= "DOS";
name= thd->make_lex_string(NULL, "table_type", 10, true); name= thd->make_lex_string(NULL, "table_type", 10, true);
val= thd->make_lex_string(NULL, typn, strlen(typn), true); val= thd->make_lex_string(NULL, typn, strlen(typn), true);
pov= new(mem) engine_option_value(*name, *val, false, &start, &end); pov= new(mem) engine_option_value(*name, *val, false, start, &end);
} // endif ttp } // endif ttp
if (!tab && !(fnc & (FNC_TABLE | FNC_COL))) if (!tab && !(fnc & (FNC_TABLE | FNC_COL)))
...@@ -3477,7 +3476,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3477,7 +3476,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
dbf= true; dbf= true;
// Passthru // Passthru
case TAB_CSV: case TAB_CSV:
if (!fn) if (!fn && fnc != FNC_NO)
sprintf(g->Message, "Missing %s file name", typn); sprintf(g->Message, "Missing %s file name", typn);
else else
ok= true; ok= true;
...@@ -3530,19 +3529,6 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3530,19 +3529,6 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
ok= false; ok= false;
} // endif supfnc } // endif supfnc
// If file name is not specified, set a default file name
// in the database directory from alias.type.
if (IsFileType(ttp) && !fn) {
char buf[256];
strcat(strcat(strcpy(buf, (char*)create_info->alias), "."), typn);
name= thd->make_lex_string(NULL, "file_name", 9, true);
val= thd->make_lex_string(NULL, buf, strlen(buf), true);
pov= new(mem) engine_option_value(*name, *val, false, &start, &end);
sprintf(g->Message, "Unspecified file name was set to %s", buf);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
} // endif ttp && fn
// Test whether columns must be specified // Test whether columns must be specified
if (alter_info->create_list.elements) if (alter_info->create_list.elements)
return false; return false;
...@@ -3849,42 +3835,69 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -3849,42 +3835,69 @@ int ha_connect::create(const char *name, TABLE *table_arg,
} // endfor field } // endfor field
// Check whether indexes were specified if (IsFileType(GetTypeID(options->type))) {
table= table_arg; // Used by called functions table= table_arg; // Used by called functions
if (!options->filename) {
// The file name is not specified, create a default file in
// the database directory named table_name.table_type.
char buf[256], fn[_MAX_PATH], dbpath[128];
int h;
strcat(strcat(strcpy(buf, GetTableName()), "."), options->type);
sprintf(g->Message, "No file name. Table will use %s", buf);
push_warning(table->in_use,
MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
strcat(strcat(strcpy(dbpath, "./"), table->s->db.str), "/");
PlugSetPath(fn, buf, dbpath);
if ((h= ::open(fn, _O_CREAT, 0666)) == -1) {
sprintf(g->Message, "Cannot create file %s", fn);
push_warning(table->in_use,
MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
} else
::close(h);
// Get the index definitions } else {
for (int n= 0; (unsigned)n < table->s->keynames.count; n++) { // Check whether indexes were specified
if (xtrace)
printf("Getting created index %d info\n", n + 1);
xdp= GetIndexInfo(n); // Get the index definitions
for (int n= 0; (unsigned)n < table->s->keynames.count; n++) {
if (xtrace)
printf("Getting created index %d info\n", n + 1);
if (pxd) xdp= GetIndexInfo(n);
pxd->SetNext(xdp);
else
toidx= xdp;
pxd= xdp; if (pxd)
} // endfor n pxd->SetNext(xdp);
else
toidx= xdp;
if (toidx) { pxd= xdp;
PDBUSER dup= PlgGetUser(g); } // endfor n
PCATLG cat= (dup) ? dup->Catalog : NULL;
DBUG_ASSERT(cat); if (toidx) {
PDBUSER dup= PlgGetUser(g);
PCATLG cat= (dup) ? dup->Catalog : NULL;
if (cat) DBUG_ASSERT(cat);
cat->SetDataPath(g, table_arg->in_use->db);
if ((rc= optimize(NULL, NULL))) { if (cat)
printf("Create rc=%d %s\n", rc, g->Message); cat->SetDataPath(g, table_arg->in_use->db);
rc= HA_ERR_INTERNAL_ERROR;
} else if ((rc= optimize(NULL, NULL))) {
CloseTable(g); printf("Create rc=%d %s\n", rc, g->Message);
rc= HA_ERR_INTERNAL_ERROR;
} else
CloseTable(g);
} // endif toidx
} // endif filename
} // endif toidx table= st;
} // endif type
table= st;
DBUG_RETURN(rc); DBUG_RETURN(rc);
} // end of create } // end of create
......
...@@ -316,7 +316,12 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef) ...@@ -316,7 +316,12 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef)
if (s) { if (s) {
sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1); sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
strcpy(sval, s); strcpy(sval, s);
} else } else if (!stricmp(what, "filename")) {
// Return default file name
sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 8);
strcat(strcpy(sval, Hc->GetTableName()), ".");
strcat(sval, Hc->GetStringOption("Type", "DOS"));
} else
sval = NULL; sval = NULL;
return sval; return sval;
......
...@@ -231,7 +231,7 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -231,7 +231,7 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
: (am && (*am == 'B' || *am == 'b')) ? "B" : (am && (*am == 'B' || *am == 'b')) ? "B"
: (am && !stricmp(am, "DBF")) ? "D" : "V"; : (am && !stricmp(am, "DBF")) ? "D" : "V";
Desc = Fn = Cat->GetStringCatInfo(g, Name, "Filename", ""); Desc = Fn = Cat->GetStringCatInfo(g, Name, "Filename", NULL);
Ofn = Cat->GetStringCatInfo(g, Name, "Optname", Fn); Ofn = Cat->GetStringCatInfo(g, Name, "Optname", Fn);
Cat->GetCharCatInfo(Name, "Recfm", (PSZ)dfm, buf, sizeof(buf)); Cat->GetCharCatInfo(Name, "Recfm", (PSZ)dfm, buf, sizeof(buf));
Recfm = (toupper(*buf) == 'F') ? RECFM_FIX : Recfm = (toupper(*buf) == 'F') ? RECFM_FIX :
......
...@@ -560,7 +560,7 @@ void TDBMUL::CloseDB(PGLOBAL g) ...@@ -560,7 +560,7 @@ void TDBMUL::CloseDB(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
bool DIRDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) bool DIRDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{ {
Desc = Fn = Cat->GetStringCatInfo(g, Name, "Filename", ""); Desc = Fn = Cat->GetStringCatInfo(g, Name, "Filename", NULL);
Incl = (Cat->GetIntCatInfo(Name, "Subdir", 0) != 0); Incl = (Cat->GetIntCatInfo(Name, "Subdir", 0) != 0);
Huge = (Cat->GetIntCatInfo(Name, "Huge", 0) != 0); Huge = (Cat->GetIntCatInfo(Name, "Huge", 0) != 0);
return false; return false;
......
...@@ -83,7 +83,7 @@ bool INIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -83,7 +83,7 @@ bool INIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
else else
strcpy(ds, "I"); // INI tables default to I(ni) strcpy(ds, "I"); // INI tables default to I(ni)
Fn = Cat->GetStringCatInfo(g, Name, "Filename", "?"); Fn = Cat->GetStringCatInfo(g, Name, "Filename", NULL);
Cat->GetCharCatInfo(Name, "Subtype", ds, buf, sizeof(buf)); Cat->GetCharCatInfo(Name, "Subtype", ds, buf, sizeof(buf));
Subtype = toupper(*buf); Subtype = toupper(*buf);
Cat->GetCharCatInfo(Name, "Layout", "C", buf, sizeof(buf)); Cat->GetCharCatInfo(Name, "Layout", "C", buf, sizeof(buf));
......
...@@ -93,7 +93,7 @@ bool XMLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -93,7 +93,7 @@ bool XMLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
//void *memp = Cat->GetDescp(); //void *memp = Cat->GetDescp();
//PSZ dbfile = Cat->GetDescFile(); //PSZ dbfile = Cat->GetDescFile();
Fn = Cat->GetStringCatInfo(g, Name, "Filename", "?"); Fn = Cat->GetStringCatInfo(g, Name, "Filename", NULL);
Encoding = Cat->GetStringCatInfo(g, Name, "Encoding", "UTF-8"); Encoding = Cat->GetStringCatInfo(g, Name, "Encoding", "UTF-8");
if (*Fn == '?') { if (*Fn == '?') {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment