318
318
const char *db_arg,
319
319
const char *table_name_arg,
320
320
const bool is_tmp_arg,
321
message::Table *table_proto_arg,
321
message::Table *table_message_arg,
323
323
session(session_arg),
326
326
table_name(table_name_arg),
327
327
is_tmp(is_tmp_arg),
328
table_proto(table_proto_arg),
328
table_message(table_message_arg),
331
331
result_type operator() (argument_type engine)
362
362
int StorageEngine::getTableDefinition(Session& session,
363
363
TableIdentifier &identifier,
364
message::Table *table_proto,
364
message::Table *table_message,
365
365
bool include_temporary_tables)
367
367
return getTableDefinition(session,
368
368
identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
369
table_proto, include_temporary_tables);
369
table_message, include_temporary_tables);
372
372
int StorageEngine::getTableDefinition(Session& session,
374
374
const char *schema_name,
375
375
const char *table_name,
377
message::Table *table_proto,
377
message::Table *table_message,
378
378
bool include_temporary_tables)
382
382
if (include_temporary_tables)
384
if (session.doGetTableDefinition(path, schema_name, table_name, false, table_proto) == EEXIST)
384
if (session.doGetTableDefinition(path, schema_name, table_name, false, table_message) == EEXIST)
388
388
EngineVector::iterator iter=
389
389
find_if(vector_of_engines.begin(), vector_of_engines.end(),
390
StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_proto, &err));
390
StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_message, &err));
392
392
if (iter == vector_of_engines.end())
514
514
@todo refactor to remove goto
516
516
int StorageEngine::createTable(Session& session,
517
TableIdentifier &identifier,
518
bool update_create_info,
519
message::Table& table_proto, bool proto_used)
517
TableIdentifier &identifier,
518
bool update_create_info,
519
message::Table& table_message)
523
523
TableShare share(identifier.getDBName(), 0, identifier.getTableName(), identifier.getPath());
524
524
message::Table tmp_proto;
528
if (parse_table_proto(session, table_proto, &share))
533
if (open_table_def(session, &share))
526
if (parse_table_proto(session, table_message, &share))
537
529
if (open_table_from_share(&session, &share, "", 0, 0,
541
533
if (update_create_info)
542
table.updateCreateInfo(&table_proto);
534
table.updateCreateInfo(&table_message);
544
536
/* Check for legal operations against the Engine using the proto (if used) */
547
if (table_proto.type() == message::Table::TEMPORARY &&
548
share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
550
error= HA_ERR_UNSUPPORTED;
553
else if (table_proto.type() != message::Table::TEMPORARY &&
554
share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
556
error= HA_ERR_UNSUPPORTED;
537
if (table_message.type() == message::Table::TEMPORARY &&
538
share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
540
error= HA_ERR_UNSUPPORTED;
543
else if (table_message.type() != message::Table::TEMPORARY &&
544
share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
546
error= HA_ERR_UNSUPPORTED;
565
554
table_name_arg= share.storage_engine->checkLowercaseNames(identifier.getPath(), name_buff);
556
if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
558
int protoerr= StorageEngine::writeDefinitionFromPath(identifier, table_message);
567
567
share.storage_engine->setTransactionReadWrite(session);
569
569
error= share.storage_engine->doCreateTable(&session,
578
if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
579
plugin::StorageEngine::deleteDefinitionFromPath(identifier);
581
my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
576
584
table.closefrm(false);
580
char name_buff[FN_REFLEN];
581
sprintf(name_buff,"%s.%s", identifier.getDBName(), identifier.getTableName());
582
my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
585
587
share.free_table_share();
586
588
return(error != 0);
1230
1232
return internal::my_rename(src_path.c_str(), dest_path.c_str(), MYF(MY_WME));
1233
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_proto)
1235
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_message)
1235
1237
string file_name(identifier.getPath());
1244
1246
google::protobuf::io::ZeroCopyOutputStream* output=
1245
1247
new google::protobuf::io::FileOutputStream(fd);
1247
if (table_proto.SerializeToZeroCopyStream(output) == false)
1249
if (table_message.SerializeToZeroCopyStream(output) == false)
1261
class CanCreateTable: public unary_function<StorageEngine *, bool>
1263
const TableIdentifier &identifier;
1266
CanCreateTable(const TableIdentifier &identifier_arg) :
1267
identifier(identifier_arg)
1270
result_type operator() (argument_type engine)
1272
return not engine->doCanCreateTable(identifier);
1278
@note on success table can be created.
1280
bool StorageEngine::canCreateTable(drizzled::TableIdentifier &identifier)
1282
EngineVector::iterator iter=
1283
find_if(vector_of_engines.begin(), vector_of_engines.end(),
1284
CanCreateTable(identifier));
1286
if (iter == vector_of_engines.end())
1259
1294
} /* namespace plugin */
1260
1295
} /* namespace drizzled */