106
110
assert(schema_message.has_collation());
108
112
// @todo push this lock down into the engine
109
pthread_mutex_lock(&LOCK_create_db);
114
boost::mutex::scoped_lock scopedLock(LOCK_create_db);
111
// Check to see if it exists already.
112
SchemaIdentifier schema_identifier(schema_message.name());
113
if (plugin::StorageEngine::doesSchemaExist(schema_identifier))
115
if (not is_if_not_exists)
117
my_error(ER_DB_CREATE_EXISTS, MYF(0), schema_message.name().c_str());
116
// Check to see if it exists already.
117
SchemaIdentifier schema_identifier(schema_message.name());
118
if (plugin::StorageEngine::doesSchemaExist(schema_identifier))
120
if (not is_if_not_exists)
122
my_error(ER_DB_CREATE_EXISTS, MYF(0), schema_message.name().c_str());
127
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
128
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS),
129
schema_message.name().c_str());
133
else if (not plugin::StorageEngine::createSchema(schema_message)) // Try to create it
135
my_error(ER_CANT_CREATE_DB, MYF(0), schema_message.name().c_str(), errno);
122
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
123
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS),
124
schema_message.name().c_str());
140
transaction_services.createSchema(session, schema_message);
128
else if (not plugin::StorageEngine::createSchema(schema_message)) // Try to create it
130
my_error(ER_CANT_CREATE_DB, MYF(0), schema_message.name().c_str(), errno);
135
transaction_services.createSchema(session, schema_message);
139
pthread_mutex_unlock(&LOCK_create_db);
140
144
start_waiting_global_read_lock(session);
164
168
if ((wait_if_global_read_lock(session, 0, 1)))
167
pthread_mutex_lock(&LOCK_create_db);
169
SchemaIdentifier schema_idenifier(schema_message.name());
170
if (not plugin::StorageEngine::doesSchemaExist(schema_idenifier))
172
my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), schema_message.name().c_str());
176
/* Change options if current database is being altered. */
177
bool success= plugin::StorageEngine::alterSchema(schema_message);
181
transaction_services.rawStatement(session, session->getQueryString());
186
my_error(ER_ALTER_SCHEMA, MYF(0), schema_message.name().c_str());
189
pthread_mutex_unlock(&LOCK_create_db);
173
boost::mutex::scoped_lock scopedLock(LOCK_create_db);
175
SchemaIdentifier schema_idenifier(schema_message.name());
176
if (not plugin::StorageEngine::doesSchemaExist(schema_idenifier))
178
my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), schema_message.name().c_str());
182
/* Change options if current database is being altered. */
183
success= plugin::StorageEngine::alterSchema(schema_message);
187
transaction_services.rawStatement(session, session->getQueryString());
192
my_error(ER_ALTER_SCHEMA, MYF(0), schema_message.name().c_str());
190
195
start_waiting_global_read_lock(session);
245
250
session->close_temporary_table(table);
248
pthread_mutex_lock(&LOCK_create_db);
251
/* See if the schema exists */
252
if (not plugin::StorageEngine::doesSchemaExist(schema_identifier))
254
boost::mutex::scoped_lock scopedLock(LOCK_create_db);
256
/* See if the schema exists */
257
if (not plugin::StorageEngine::doesSchemaExist(schema_identifier))
256
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
257
ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS),
258
schema_identifier.getSQLPath().c_str());
261
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
262
ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS),
263
schema_identifier.getSQLPath().c_str());
268
my_error(ER_DB_DROP_EXISTS, MYF(0), schema_identifier.getSQLPath().c_str());
274
LOCK_open.lock(); /* After deleting database, remove all cache entries related to schema */
275
remove_db_from_cache(schema_identifier);
263
my_error(ER_DB_DROP_EXISTS, MYF(0), schema_identifier.getSQLPath().c_str());
280
deleted= drop_tables_via_filenames(session, schema_identifier, dropped_tables);
269
pthread_mutex_lock(&LOCK_open); /* After deleting database, remove all cache entries related to schema */
270
remove_db_from_cache(schema_identifier);
271
pthread_mutex_unlock(&LOCK_open);
275
deleted= mysql_rm_known_files(session, schema_identifier, dropped_tables);
276
286
if (deleted >= 0)
288
assert(! session->query.empty());
290
TransactionServices &transaction_services= TransactionServices::singleton();
291
transaction_services.dropSchema(session, schema_identifier.getSchemaName());
292
session->clear_error();
293
session->server_status|= SERVER_STATUS_DB_DROPPED;
294
session->my_ok((uint32_t) deleted);
295
session->server_status&= ~SERVER_STATUS_DB_DROPPED;
283
assert(! session->query.empty());
285
TransactionServices &transaction_services= TransactionServices::singleton();
286
transaction_services.dropSchema(session, schema_identifier.getSchemaName());
287
session->clear_error();
288
session->server_status|= SERVER_STATUS_DB_DROPPED;
289
session->my_ok((uint32_t) deleted);
290
session->server_status&= ~SERVER_STATUS_DB_DROPPED;
294
char *query, *query_pos, *query_end, *query_data_start;
296
if (!(query= (char*) session->alloc(MAX_DROP_TABLE_Q_LEN)))
297
goto exit; /* not much else we can do */
298
query_pos= query_data_start= strcpy(query,"drop table ")+11;
299
query_end= query + MAX_DROP_TABLE_Q_LEN;
301
TransactionServices &transaction_services= TransactionServices::singleton();
302
for (plugin::TableNameList::iterator it= dropped_tables.begin();
303
it != dropped_tables.end();
306
uint32_t tbl_name_len;
308
/* 3 for the quotes and the comma*/
309
tbl_name_len= (*it).length() + 3;
310
if (query_pos + tbl_name_len + 1 >= query_end)
299
char *query, *query_pos, *query_end, *query_data_start;
301
if (!(query= (char*) session->alloc(MAX_DROP_TABLE_Q_LEN)))
302
goto exit; /* not much else we can do */
303
query_pos= query_data_start= strcpy(query,"drop table ")+11;
304
query_end= query + MAX_DROP_TABLE_Q_LEN;
306
TransactionServices &transaction_services= TransactionServices::singleton();
307
for (TableIdentifiers::iterator it= dropped_tables.begin();
308
it != dropped_tables.end();
311
uint32_t tbl_name_len;
313
/* 3 for the quotes and the comma*/
314
tbl_name_len= (*it).getTableName().length() + 3;
315
if (query_pos + tbl_name_len + 1 >= query_end)
317
/* These DDL methods and logging protected with LOCK_create_db */
318
transaction_services.rawStatement(session, query);
319
query_pos= query_data_start;
323
query_pos= strcpy(query_pos, (*it).getTableName().c_str()) + (tbl_name_len-3);
328
if (query_pos != query_data_start)
312
330
/* These DDL methods and logging protected with LOCK_create_db */
313
331
transaction_services.rawStatement(session, query);
314
query_pos= query_data_start;
318
query_pos= strcpy(query_pos, (*it).c_str()) + (tbl_name_len-3);
323
if (query_pos != query_data_start)
325
/* These DDL methods and logging protected with LOCK_create_db */
326
transaction_services.rawStatement(session, query);
332
If this database was the client's selected database, we silently
333
change the client's selected database to nothing (to have an empty
334
SELECT DATABASE() in the future). For this we free() session->db and set
337
if (schema_identifier.compare(session->db))
338
mysql_change_db_impl(session);
339
pthread_mutex_unlock(&LOCK_create_db);
337
If this database was the client's selected database, we silently
338
change the client's selected database to nothing (to have an empty
339
SELECT DATABASE() in the future). For this we free() session->db and set
342
if (schema_identifier.compare(session->db))
343
mysql_change_db_impl(session);
340
346
start_waiting_global_read_lock(session);
394
goto err_with_placeholders;
402
unlock_table_names(tables, NULL);
404
session->no_warnings_for_error= 0;
396
408
// temporary table not found
400
table_type= table->db_type;
412
table_type= table->getDbType();
414
TableIdentifier identifier(db, table->table_name);
403
417
Table *locked_table;
404
abort_locked_tables(session, db, table->table_name);
405
remove_table_from_cache(session, db, table->table_name,
418
abort_locked_tables(session, identifier);
419
remove_table_from_cache(session, identifier,
406
420
RTFC_WAIT_OTHER_THREAD_FLAG |
407
421
RTFC_CHECK_KILLED_FLAG);
409
423
If the table was used in lock tables, remember it so that
410
424
unlock_table_names can free it
412
if ((locked_table= drop_locked_tables(session, db, table->table_name)))
426
if ((locked_table= drop_locked_tables(session, identifier)))
413
427
table->table= locked_table;
415
429
if (session->killed)
418
goto err_with_placeholders;
432
unlock_table_names(tables, NULL);
434
session->no_warnings_for_error= 0;
422
TableIdentifier identifier(db, table->table_name);
423
439
identifier.getPath();
425
441
if (table_type == NULL && not plugin::StorageEngine::doesTableExist(*session, identifier))
488
505
session MUST be set when calling this function!
491
static long mysql_rm_known_files(Session *session,
492
SchemaIdentifier &schema_identifier,
493
plugin::TableNameList &dropped_tables)
508
static long drop_tables_via_filenames(Session *session,
509
SchemaIdentifier &schema_identifier,
510
TableIdentifiers &dropped_tables)
496
513
TableList *tot_list= NULL, **tot_list_next;
498
515
tot_list_next= &tot_list;
500
plugin::StorageEngine::getTableNames(*session, schema_identifier, dropped_tables);
517
plugin::StorageEngine::getIdentifiers(*session, schema_identifier, dropped_tables);
502
for (plugin::TableNameList::iterator it= dropped_tables.begin();
519
for (TableIdentifiers::iterator it= dropped_tables.begin();
503
520
it != dropped_tables.end();
509
526
TableList *table_list=(TableList*)
510
527
session->calloc(sizeof(*table_list) +
529
(*it).getTableName().length() + 1);
514
531
if (not table_list)
517
534
table_list->db= (char*) (table_list+1);
518
535
table_list->table_name= strcpy(table_list->db, schema_identifier.getSchemaName().c_str()) + db_len + 1;
519
filename_to_tablename((*it).c_str(), table_list->table_name,
536
TableIdentifier::filename_to_tablename((*it).getTableName().c_str(), table_list->table_name, (*it).getTableName().size() + 1);
521
537
table_list->alias= table_list->table_name; // If lower_case_table_names=2
522
table_list->internal_tmp_table= (strncmp((*it).c_str(),
538
table_list->setInternalTmpTable((strncmp((*it).getTableName().c_str(),
524
strlen(TMP_FILE_PREFIX)) == 0);
540
strlen(TMP_FILE_PREFIX)) == 0));
525
541
/* Link into list */
526
542
(*tot_list_next)= table_list;
527
543
tot_list_next= &table_list->next_local;