84
84
let's fetch the database default character set and
85
85
apply it to the table.
87
SchemaIdentifier identifier(db);
88
87
if (create_info->default_table_charset == NULL)
89
create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
88
create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(db);
237
236
goto err_with_placeholders;
240
TableIdentifier identifier(db, table->table_name, table->internal_tmp_table ? message::Table::INTERNAL : message::Table::STANDARD);
239
TableIdentifier identifier(db, table->table_name, table->internal_tmp_table ? INTERNAL_TMP_TABLE : STANDARD_TABLE);
242
241
if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, identifier))
286
285
pthread_mutex_unlock(&LOCK_open);
289
287
if (wrong_tables.length())
291
if (not foreign_key_error)
289
if (!foreign_key_error)
293
290
my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0),
294
291
wrong_tables.c_ptr());
298
294
my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0));
303
299
pthread_mutex_lock(&LOCK_open); /* final bit in rm table lock */
305
300
err_with_placeholders:
306
301
unlock_table_names(tables, NULL);
307
302
pthread_mutex_unlock(&LOCK_open);
308
303
session->no_warnings_for_error= 0;
1307
1303
to create a table under a temporary table.
1310
plugin::StorageEngine::doesTableExist(*session, identifier,
1311
identifier.getType() != message::Table::STANDARD );
1306
plugin::StorageEngine::doesTableExist(*session, identifier, lex_identified_temp_table);
1325
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1320
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getTableName().c_str());
1329
if (identifier.getType() == message::Table::STANDARD) // We have a real table
1324
if (not lex_identified_temp_table) // We have a real table
1332
1327
We don't assert here, but check the result, because the table could be
1342
1337
if (TableShare::getShare(identifier))
1344
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1339
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getTableName().c_str());
1443
1440
if (create_info->row_type == ROW_TYPE_DYNAMIC)
1444
1441
db_options|=HA_OPTION_PACK_RECORD;
1446
set_table_default_charset(create_info, identifier.getSchemaName().c_str());
1443
set_table_default_charset(create_info, identifier.getDBName().c_str());
1448
1445
/* Build a Table object to pass down to the engine, and the do the actual create. */
1449
1446
if (not mysql_prepare_create_table(session, create_info, table_proto, alter_info,
1540
1538
uint32_t select_field_count,
1541
1539
bool is_if_not_exists)
1543
if (identifier.isTmp())
1541
bool lex_identified_temp_table=
1542
(table_proto.type() == message::Table::TEMPORARY);
1544
if (lex_identified_temp_table)
1545
1546
return mysql_create_table_no_lock(session,
1631
mysql_rename_table(plugin::StorageEngine *base,
1632
TableIdentifier &from,
1633
TableIdentifier &to,
1634
mysql_rename_table(plugin::StorageEngine *base, const char *old_db,
1635
const char *old_name, const char *new_db,
1636
const char *new_name, uint32_t flags)
1636
1638
Session *session= current_session;
1641
if (not plugin::StorageEngine::doesSchemaExist(to))
1645
build_table_filename(from, old_db, old_name,
1646
flags & FN_FROM_IS_TMP);
1647
build_table_filename(to, new_db, new_name,
1648
flags & FN_TO_IS_TMP);
1650
if (!(error= base->renameTable(session, from.c_str(), to.c_str())))
1643
my_error(ER_NO_DB_ERROR, MYF(0), to.getSchemaName().c_str());
1652
if (base->check_flag(HTON_BIT_HAS_DATA_DICTIONARY) == 0
1653
&& rename_table_proto_file(from.c_str(), to.c_str()))
1656
base->renameTable(session, to.c_str(), from.c_str());
1647
error= base->renameTable(*session, from, to);
1649
1660
if (error == HA_ERR_WRONG_COMMAND)
1651
1661
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table");
1653
1662
else if (error)
1655
const char *from_identifier= from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str();
1656
const char *to_identifier= to.isTmp() ? "#sql-temporary" : to.getSQLPath().c_str();
1658
my_error(ER_ERROR_ON_RENAME, MYF(0), from_identifier, to_identifier, error);
1661
return error ? true : false;
1663
my_error(ER_ERROR_ON_RENAME, MYF(0), from.c_str(), to.c_str(), error);
1775
1779
char* db = table->db;
1776
1780
bool fatal_error=0;
1778
snprintf(table_name, sizeof(table_name), "%s.%s",db,table->table_name);
1782
sprintf(table_name,"%s.%s",db,table->table_name);
1779
1783
table->lock_type= lock_type;
1780
1784
/* open only one table from local list of command */
2042
2046
during the call to plugin::StorageEngine::createTable().
2043
2047
See bug #28614 for more info.
2045
static bool create_table_wrapper(Session &session, const message::Table& create_table_proto,
2049
static bool create_table_wrapper(Session &session, message::Table& create_table_proto,
2046
2050
TableIdentifier &destination_identifier,
2047
2051
TableIdentifier &src_table,
2052
bool lex_identified_temp_table, bool is_engine_set)
2050
2054
int protoerr= EEXIST;
2051
2055
message::Table new_proto;
2073
2077
protoengine->set_name(create_table_proto.engine().name());
2076
{ // We now do a selective copy of elements on to the new table.
2077
new_proto.set_name(create_table_proto.name());
2078
new_proto.set_schema(create_table_proto.schema());
2079
new_proto.set_catalog(create_table_proto.catalog());
2082
2080
if (protoerr && protoerr != EEXIST)
2084
2082
if (errno == ENOENT)
2119
2117
bool mysql_create_like_table(Session* session,
2120
2118
TableIdentifier &destination_identifier,
2121
2119
TableList* table, TableList* src_table,
2122
message::Table &create_table_proto,
2120
message::Table& create_table_proto,
2123
2121
bool is_if_not_exists,
2124
2122
bool is_engine_set)
2152
2152
was already checked when it was added to the table list.
2154
2154
bool table_exists= false;
2155
if (destination_identifier.isTmp())
2155
if (lex_identified_temp_table)
2157
2157
if (session->find_temporary_table(db, table_name))
2204
2204
pthread_mutex_lock(&LOCK_open); /* We lock for CREATE TABLE LIKE to copy table definition */
2205
2205
was_created= create_table_wrapper(*session, create_table_proto, destination_identifier,
2206
src_identifier, is_engine_set);
2206
src_identifier, lex_identified_temp_table, is_engine_set);
2207
2207
pthread_mutex_unlock(&LOCK_open);
2209
2209
// So we blew the creation of the table, and we scramble to clean up
2210
2210
// anything that might have been created (read... it is a hack)
2211
2211
if (not was_created)
2213
if (destination_identifier.isTmp())
2213
if (lex_identified_temp_table)
2215
2215
(void) session->rm_temporary_table(destination_identifier);
2219
2219
quick_rm_table(*session, destination_identifier);
2222
else if (destination_identifier.isTmp() && not session->open_temporary_table(destination_identifier))
2222
else if (lex_identified_temp_table && not session->open_temporary_table(destination_identifier))
2224
2224
// We created, but we can't open... also, a hack.
2225
2225
(void) session->rm_temporary_table(destination_identifier);
2229
if (not destination_identifier.isTmp())
2229
if (not lex_identified_temp_table)
2231
2231
bool rc= replicateCreateTableLike(session, table, name_lock, (src_table->table->s->tmp_table), is_if_not_exists);
2289
2289
char table_name[NAME_LEN*2+2];
2292
snprintf(table_name, sizeof(table_name), "%s.%s",table->db,table->table_name);
2292
sprintf(table_name,"%s.%s",table->db,table->table_name);
2294
2294
t= table->table= session->openTableLock(table, TL_READ);
2295
2295
session->clear_error(); // these errors shouldn't get client