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
pthread_mutex_lock(&LOCK_open); /* After deleting database, remove all cache entries related to schema */
275
remove_db_from_cache(schema_identifier);
276
pthread_mutex_unlock(&LOCK_open);
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= drop_tables_via_filenames(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 (TableIdentifiers::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).getTableName().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).getTableName().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);