mirror of
https://github.com/MariaDB/server.git
synced 2025-03-30 20:05:38 +02:00
- 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
This commit is contained in:
parent
a2ca685661
commit
7572315ecd
6 changed files with 69 additions and 51 deletions
|
@ -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,42 +3835,69 @@ int ha_connect::create(const char *name, TABLE *table_arg,
|
|||
|
||||
} // endfor field
|
||||
|
||||
// Check whether indexes were specified
|
||||
table= table_arg; // Used by called functions
|
||||
if (IsFileType(GetTypeID(options->type))) {
|
||||
table= table_arg; // Used by called functions
|
||||
|
||||
// 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 (!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;
|
||||
|
||||
xdp= GetIndexInfo(n);
|
||||
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 (pxd)
|
||||
pxd->SetNext(xdp);
|
||||
else
|
||||
toidx= xdp;
|
||||
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);
|
||||
|
||||
pxd= xdp;
|
||||
} // endfor n
|
||||
} else {
|
||||
// Check whether indexes were specified
|
||||
|
||||
if (toidx) {
|
||||
PDBUSER dup= PlgGetUser(g);
|
||||
PCATLG cat= (dup) ? dup->Catalog : NULL;
|
||||
// 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);
|
||||
|
||||
DBUG_ASSERT(cat);
|
||||
xdp= GetIndexInfo(n);
|
||||
|
||||
if (cat)
|
||||
cat->SetDataPath(g, table_arg->in_use->db);
|
||||
if (pxd)
|
||||
pxd->SetNext(xdp);
|
||||
else
|
||||
toidx= xdp;
|
||||
|
||||
if ((rc= optimize(NULL, NULL))) {
|
||||
printf("Create rc=%d %s\n", rc, g->Message);
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
} else
|
||||
CloseTable(g);
|
||||
pxd= xdp;
|
||||
} // endfor n
|
||||
|
||||
} // endif toidx
|
||||
if (toidx) {
|
||||
PDBUSER dup= PlgGetUser(g);
|
||||
PCATLG cat= (dup) ? dup->Catalog : NULL;
|
||||
|
||||
DBUG_ASSERT(cat);
|
||||
|
||||
if (cat)
|
||||
cat->SetDataPath(g, table_arg->in_use->db);
|
||||
|
||||
if ((rc= optimize(NULL, NULL))) {
|
||||
printf("Create rc=%d %s\n", rc, g->Message);
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
} else
|
||||
CloseTable(g);
|
||||
|
||||
} // endif toidx
|
||||
|
||||
} // endif filename
|
||||
|
||||
table= st;
|
||||
} // endif type
|
||||
|
||||
table= st;
|
||||
DBUG_RETURN(rc);
|
||||
} // end of create
|
||||
|
||||
|
|
|
@ -316,7 +316,12 @@ 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
|
||||
} 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;
|
||||
|
||||
return sval;
|
||||
|
|
|
@ -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 == '?') {
|
||||
|
|
Loading…
Add table
Reference in a new issue