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 @@
#include "tabcol.h"
#include "xindex.h"
#if defined(WIN32)
#include <io.h>
#include "tabwmi.h"
#endif // WIN32
#include "connect.h"
......@@ -3388,7 +3389,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
MEM_ROOT *mem= thd->mem_root;
CHARSET_INFO *cs;
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;
PCOLRES crp;
PGLOBAL g= GetPlug(thd);
......@@ -3400,7 +3401,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
user= NULL;
// 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")) {
typn= pov->value.str;
ttp= GetTypeID(typn);
......@@ -3447,15 +3448,13 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
// Check table type
if (ttp == TAB_UNDEF || ttp == TAB_NIY) {
sprintf(g->Message, "Unknown Table_type '%s'", typn);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
strcpy(g->Message, "Using Table_type DOS");
strcpy(g->Message, "No table_type. Was set to DOS");
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
ttp= TAB_DOS;
typn= "DOS";
name= thd->make_lex_string(NULL, "table_type", 10, 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
if (!tab && !(fnc & (FNC_TABLE | FNC_COL)))
......@@ -3477,7 +3476,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
dbf= true;
// Passthru
case TAB_CSV:
if (!fn)
if (!fn && fnc != FNC_NO)
sprintf(g->Message, "Missing %s file name", typn);
else
ok= true;
......@@ -3530,19 +3529,6 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
ok= false;
} // 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
if (alter_info->create_list.elements)
return false;
......@@ -3849,9 +3835,32 @@ int ha_connect::create(const char *name, TABLE *table_arg,
} // endfor field
// Check whether indexes were specified
if (IsFileType(GetTypeID(options->type))) {
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);
} else {
// Check whether indexes were specified
// Get the index definitions
for (int n= 0; (unsigned)n < table->s->keynames.count; n++) {
if (xtrace)
......@@ -3884,7 +3893,11 @@ int ha_connect::create(const char *name, TABLE *table_arg,
} // endif toidx
} // endif filename
table= st;
} // endif type
DBUG_RETURN(rc);
} // end of create
......
......@@ -316,6 +316,11 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef)
if (s) {
sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
strcpy(sval, s);
} 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;
......
......@@ -231,7 +231,7 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
: (am && (*am == 'B' || *am == 'b')) ? "B"
: (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);
Cat->GetCharCatInfo(Name, "Recfm", (PSZ)dfm, buf, sizeof(buf));
Recfm = (toupper(*buf) == 'F') ? RECFM_FIX :
......
......@@ -560,7 +560,7 @@ void TDBMUL::CloseDB(PGLOBAL g)
/***********************************************************************/
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);
Huge = (Cat->GetIntCatInfo(Name, "Huge", 0) != 0);
return false;
......
......@@ -83,7 +83,7 @@ bool INIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
else
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));
Subtype = toupper(*buf);
Cat->GetCharCatInfo(Name, "Layout", "C", buf, sizeof(buf));
......
......@@ -93,7 +93,7 @@ bool XMLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
//void *memp = Cat->GetDescp();
//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");
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