diff options
author | unknown <magnus@neptunus.(none)> | 2004-09-20 14:28:43 +0200 |
---|---|---|
committer | unknown <magnus@neptunus.(none)> | 2004-09-20 14:28:43 +0200 |
commit | bdbb091b68087587f42a16923b42921eb44744b1 (patch) | |
tree | d9c8ecc32b0f9ad9899a1ddcf30826b5c313bcfb /sql/handler.cc | |
parent | 7f1fcf6648c6c4a29b94360fd47f53e90812cb98 (diff) | |
parent | 877ba4489a74fe59ecf8a4a9d896204b923e42ac (diff) | |
download | mariadb-git-bdbb091b68087587f42a16923b42921eb44744b1.tar.gz |
Merged Thd_ndb
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
Auto merged
sql/ha_ndbcluster.h:
Auto merged
sql/handler.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_table.cc:
Auto merged
Diffstat (limited to 'sql/handler.cc')
-rw-r--r-- | sql/handler.cc | 142 |
1 files changed, 138 insertions, 4 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index 859c7124566..adecf135347 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1119,6 +1119,16 @@ void handler::print_error(int error, myf errflag) case HA_ERR_NO_REFERENCED_ROW: textno=ER_NO_REFERENCED_ROW; break; + case HA_ERR_NO_SUCH_TABLE: + { + char *db; + char buff[FN_REFLEN]; + uint length=dirname_part(buff,table->path); + buff[length-1]=0; + db=buff+dirname_length(buff); + my_error(ER_NO_SUCH_TABLE,MYF(0),db,table->table_name); + break; + } default: { /* The error was "unknown" to this function. @@ -1265,6 +1275,71 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, DBUG_RETURN(error != 0); } +/* + Try to discover table from engine and + if found, write the frm file to disk. + + RETURN VALUES: + 0 : Table existed in engine and created + on disk if so requested + 1 : Table does not exist + >1 : error + +*/ + +int ha_create_table_from_engine(THD* thd, + const char *db, + const char *name, + bool create_if_found) +{ + int error= 0; + const void* frmblob = NULL; + uint frmlen = 0; + char path[FN_REFLEN]; + HA_CREATE_INFO create_info; + TABLE table; + DBUG_ENTER("ha_create_table_from_engine"); + DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); + DBUG_PRINT("enter", ("create_if_found: %d", create_if_found)); + + bzero((char*) &create_info,sizeof(create_info)); + + if ((error= ha_discover(thd, db, name, &frmblob, &frmlen))) + DBUG_RETURN(error); + + // Table exists in handler + if (create_if_found) + { + (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS); + // Save the frm file + if ((error = writefrm(path, frmblob, frmlen))) + goto err_end; + + if (openfrm(path,"",0,(uint) READ_ALL, 0, &table)) + DBUG_RETURN(1); + + update_create_info_from_table(&create_info, &table); + create_info.table_options|= HA_CREATE_FROM_ENGINE; + + if (lower_case_table_names == 2 && + !(table.file->table_flags() & HA_FILE_BASED)) + { + /* Ensure that handler gets name in lower case */ + strmov(path, name); + my_casedn_str(files_charset_info, path); + name= path; + } + + error=table.file->create(path,&table,&create_info); + VOID(closefrm(&table)); + } + +err_end: + if (frmblob) + my_free((char*) frmblob,MYF(0)); + DBUG_RETURN(error); +} + static int NEAR_F delete_file(const char *name,const char *ext,int extflag) { char buff[FN_REFLEN]; @@ -1372,15 +1447,15 @@ int ha_change_key_cache(KEY_CACHE *old_key_cache, Try to discover one table from handler(s) */ -int ha_discover(const char* dbname, const char* name, - const void** frmblob, uint* frmlen) +int ha_discover(THD* thd, const char* db, const char* name, + const void** frmblob, uint* frmlen) { int error= 1; // Table does not exist in any handler DBUG_ENTER("ha_discover"); - DBUG_PRINT("enter", ("db: %s, name: %s", dbname, name)); + DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); #ifdef HAVE_NDBCLUSTER_DB if (have_ndbcluster == SHOW_OPTION_YES) - error= ndbcluster_discover(dbname, name, frmblob, frmlen); + error= ndbcluster_discover(thd, db, name, frmblob, frmlen); #endif if (!error) statistic_increment(ha_discover_count,&LOCK_status); @@ -1389,6 +1464,65 @@ int ha_discover(const char* dbname, const char* name, /* + Ask handler if it would support discover of a file + with this name + + RETURN + 0 Does not recognise file + 1 File can be discovered +*/ + +int ha_can_discover(THD* thd, const char* name) +{ + int error= 0; // Can't discover this file name + DBUG_ENTER("ha_can_discover"); + DBUG_PRINT("enter", ("name: %s", name)); +#ifdef HAVE_NDBCLUSTER_DB + if (have_ndbcluster == SHOW_OPTION_YES) + error= ndbcluster_can_discover(thd, name); +#endif + DBUG_RETURN(error); +} + +/* + Get a list of tables that exists in handler(s) + */ +int ha_list_tables(THD* thd, HASH *tables, const char* db) +{ + int error= 0; + DBUG_ENTER("ha_list_tables"); + DBUG_PRINT("enter", ("db: %s", db)); +#ifdef HAVE_NDBCLUSTER_DB + if (have_ndbcluster == SHOW_OPTION_YES) + error= ndbcluster_list_tables(thd, tables, db); +#endif + DBUG_RETURN(error); +} + +/* + Ask handler if the table exists in engine + + RETURN + 0 Table does not exist + 1 Table exists + # Error code + + */ +int ha_table_exists(THD* thd, const char* db, const char* name) +{ + int error= 2; + DBUG_ENTER("ha_table_exists"); + DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); +#ifdef HAVE_NDBCLUSTER_DB + if (have_ndbcluster == SHOW_OPTION_YES) + error= ndbcluster_table_exists(thd, db, name); +#endif + DBUG_RETURN(error); +} + + + +/* Read first row between two ranges. Store ranges for future calls to read_range_next |