67
67
static EngineVector vector_of_engines;
68
68
static EngineVector vector_of_schema_engines;
69
static EngineVector vector_of_data_dictionary;
70
71
const std::string UNKNOWN_STRING("UNKNOWN");
71
72
const std::string DEFAULT_DEFINITION_FILE_EXT(".dfe");
128
int StorageEngine::doDropTable(Session&,
129
const string &table_path)
129
int StorageEngine::doDropTable(Session&, TableIdentifier &identifier)
132
133
int enoent_or_zero= ENOENT; // Error if no file was deleted
135
136
for (const char **ext= bas_ext(); *ext ; ext++)
137
internal::fn_format(buff, table_path.c_str(), "", *ext,
138
MY_UNPACK_FILENAME|MY_APPEND_EXT);
138
internal::fn_format(buff, identifier.getPath().c_str(), "", *ext,
139
MY_UNPACK_FILENAME|MY_APPEND_EXT);
139
140
if (internal::my_delete_with_symlink(buff, MYF(0)))
141
142
if ((error= errno) != ENOENT)
151
const char *StorageEngine::checkLowercaseNames(const char *path,
154
if (flags.test(HTON_BIT_FILE_BASED))
157
/* Ensure that table Cursor get path in lower case */
158
if (tmp_path != path)
159
strcpy(tmp_path, path);
162
we only should turn into lowercase database/table part
163
so start the process after homedirectory
165
if (strstr(tmp_path, drizzle_tmpdir) == tmp_path)
166
my_casedn_str(files_charset_info, tmp_path + strlen(drizzle_tmpdir));
168
my_casedn_str(files_charset_info, tmp_path + drizzle_data_home_len);
174
152
bool StorageEngine::addPlugin(StorageEngine *engine)
306
288
class StorageEngineGetTableDefinition: public unary_function<StorageEngine *,bool>
308
290
Session& session;
311
const char *table_name;
313
message::Table *table_message;
291
TableIdentifier &identifier;
292
message::Table &table_message;
317
296
StorageEngineGetTableDefinition(Session& session_arg,
318
const char* path_arg,
320
const char *table_name_arg,
321
const bool is_tmp_arg,
322
message::Table *table_message_arg,
297
TableIdentifier &identifier_arg,
298
message::Table &table_message_arg,
324
300
session(session_arg),
327
table_name(table_name_arg),
301
identifier(identifier_arg),
329
302
table_message(table_message_arg),
332
305
result_type operator() (argument_type engine)
334
307
int ret= engine->doGetTableDefinition(session,
341
311
if (ret != ENOENT)
318
class StorageEngineDoesTableExist: public unary_function<StorageEngine *, bool>
321
TableIdentifier &identifier;
324
StorageEngineDoesTableExist(Session& session_arg, TableIdentifier &identifier_arg) :
325
session(session_arg),
326
identifier(identifier_arg)
329
result_type operator() (argument_type engine)
331
return engine->doDoesTableExist(session, identifier);
349
336
Utility method which hides some of the details of getTableDefinition()
351
bool plugin::StorageEngine::doesTableExist(Session& session,
338
bool plugin::StorageEngine::doesTableExist(Session &session,
352
339
TableIdentifier &identifier,
353
340
bool include_temporary_tables)
355
return (plugin::StorageEngine::getTableDefinition(session, identifier, NULL, include_temporary_tables) == EEXIST);
342
if (include_temporary_tables)
344
if (session.doDoesTableExist(identifier))
348
EngineVector::iterator iter=
349
find_if(vector_of_data_dictionary.begin(), vector_of_data_dictionary.end(),
350
StorageEngineDoesTableExist(session, identifier));
352
if (iter == vector_of_data_dictionary.end())
360
bool plugin::StorageEngine::doDoesTableExist(Session&, TableIdentifier&)
362
cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
363
372
int StorageEngine::getTableDefinition(Session& session,
364
373
TableIdentifier &identifier,
365
message::Table *table_message,
374
message::Table &table_message,
366
375
bool include_temporary_tables)
368
return getTableDefinition(session,
369
identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
370
table_message, include_temporary_tables);
373
int StorageEngine::getTableDefinition(Session& session,
375
const char *schema_name,
376
const char *table_name,
378
message::Table *table_message,
379
bool include_temporary_tables)
383
379
if (include_temporary_tables)
385
if (session.doGetTableDefinition(path, schema_name, table_name, false, table_message) == EEXIST)
381
if (session.doGetTableDefinition(identifier, table_message) == EEXIST)
389
385
EngineVector::iterator iter=
390
386
find_if(vector_of_engines.begin(), vector_of_engines.end(),
391
StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_message, &err));
387
StorageEngineGetTableDefinition(session, identifier, table_message, &err));
393
389
if (iter == vector_of_engines.end())
449
445
// @todo someday check that at least one engine said "true"
450
446
std::string path(identifier.getPath());
451
bool success= engine->doDropTable(session, path);
447
bool success= engine->doDropTable(session, identifier, path);
467
463
message::Table src_proto;
468
464
StorageEngine* engine;
470
error_proto= StorageEngine::getTableDefinition(session,
466
error_proto= StorageEngine::getTableDefinition(session, identifier, src_proto);
474
468
if (error_proto == ER_CORRUPT_TABLE_DEFINITION)
485
479
std::string path(identifier.getPath());
486
480
engine->setTransactionReadWrite(session);
487
error= engine->doDropTable(session, path);
481
error= engine->doDropTable(session, identifier, path);
524
TableShare share(identifier.getDBName(), 0, identifier.getTableName(), identifier.getPath());
518
TableShare share(identifier.getDBName().c_str(), 0, identifier.getTableName().c_str(), identifier.getPath().c_str());
525
519
message::Table tmp_proto;
527
521
if (parse_table_proto(session, table_message, &share))
552
char name_buff[FN_REFLEN];
553
const char *table_name_arg;
555
table_name_arg= share.storage_engine->checkLowercaseNames(identifier.getPath(), name_buff);
557
546
if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
559
548
int protoerr= StorageEngine::writeDefinitionFromPath(identifier, table_message);
822
811
void StorageEngine::getTableNames(const string &schema_name, TableNameList &set_of_names)
824
char tmp_path[FN_REFLEN];
826
build_table_filename(tmp_path, sizeof(tmp_path), schema_name.c_str(), "", false);
815
build_table_filename(tmp_path, schema_name.c_str(), "", false);
828
817
CachedDirectory directory(tmp_path, set_of_table_definition_ext);
869
858
result_type operator() (argument_type engine)
872
860
for (TableNameList::iterator iter= set_of_names.begin();
873
861
iter != set_of_names.end();
876
int error= engine->doDropTable(session, *iter);
864
TableIdentifier dummy((*iter).c_str());
865
int error= engine->doDropTable(session, dummy, *iter);
878
867
// On a return of zero we know we found and deleted the table. So we
879
868
// remove it from our search.
1113
1102
case HA_ERR_NO_SUCH_TABLE:
1115
my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->db.str,
1104
my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->getSchemaName(),
1116
1105
table->s->table_name.str);
1118
1107
case HA_ERR_RBR_LOGGING_FAILED: