diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2013-03-12 01:20:52 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2013-03-12 01:20:52 +0100 |
commit | 7572315ecd64974f5d8faf4cac44a10aca0a4a9f (patch) | |
tree | eef50a03b61d59e6a86a3de62753e1ba6f2bb594 /storage | |
parent | a2ca685661c724819e9e81468529763f039c3e92 (diff) | |
download | mariadb-git-7572315ecd64974f5d8faf4cac44a10aca0a4a9f.tar.gz |
- 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
Diffstat (limited to 'storage')
-rw-r--r-- | storage/connect/ha_connect.cc | 105 | ||||
-rw-r--r-- | storage/connect/mycat.cc | 7 | ||||
-rw-r--r-- | storage/connect/tabdos.cpp | 2 | ||||
-rw-r--r-- | storage/connect/tabmul.cpp | 2 | ||||
-rw-r--r-- | storage/connect/tabsys.cpp | 2 | ||||
-rw-r--r-- | storage/connect/tabxml.cpp | 2 |
6 files changed, 69 insertions, 51 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 61d2f6271a9..380e00c1961 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -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 + + 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 - for (int n= 0; (unsigned)n < table->s->keynames.count; n++) { - if (xtrace) - printf("Getting created index %d info\n", n + 1); + } else { + // Check whether indexes were specified - 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) - pxd->SetNext(xdp); - else - toidx= xdp; + xdp= GetIndexInfo(n); - pxd= xdp; - } // endfor n + if (pxd) + pxd->SetNext(xdp); + else + toidx= xdp; - if (toidx) { - PDBUSER dup= PlgGetUser(g); - PCATLG cat= (dup) ? dup->Catalog : NULL; + pxd= xdp; + } // endfor n - DBUG_ASSERT(cat); + if (toidx) { + PDBUSER dup= PlgGetUser(g); + PCATLG cat= (dup) ? dup->Catalog : NULL; - if (cat) - cat->SetDataPath(g, table_arg->in_use->db); + DBUG_ASSERT(cat); - if ((rc= optimize(NULL, NULL))) { - printf("Create rc=%d %s\n", rc, g->Message); - rc= HA_ERR_INTERNAL_ERROR; - } else - CloseTable(g); + 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 - } // endif toidx + table= st; + } // endif type - table= st; DBUG_RETURN(rc); } // end of create diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index aa47decda46..30a743f3df9 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -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; diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp index c3ac9d08911..45603b23aa6 100644 --- a/storage/connect/tabdos.cpp +++ b/storage/connect/tabdos.cpp @@ -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 : diff --git a/storage/connect/tabmul.cpp b/storage/connect/tabmul.cpp index 3fc612b50f9..2715ced81be 100644 --- a/storage/connect/tabmul.cpp +++ b/storage/connect/tabmul.cpp @@ -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; diff --git a/storage/connect/tabsys.cpp b/storage/connect/tabsys.cpp index e2e756128cf..90d104521f5 100644 --- a/storage/connect/tabsys.cpp +++ b/storage/connect/tabsys.cpp @@ -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)); diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index 08deb7c9fa8..6099f9bffae 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -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 == '?') { |