62
62
static void mysql_change_db_impl(Session *session, LEX_STRING *new_db_name);
64
64
/* path is path to database, not schema file */
65
static int write_schema_file(const char *path, const message::Schema &db)
65
int write_schema_file(const char *path, const message::Schema &db)
67
67
char schema_file_tmp[FN_REFLEN];
68
68
string schema_file(path);
119
bool mysql_create_db(Session *session, const char *db, message::Schema *schema_message, bool is_if_not_exists)
119
bool mysql_create_db(Session *session, message::Schema &schema_message, bool is_if_not_exists)
121
121
ReplicationServices &replication_services= ReplicationServices::singleton();
124
122
bool error= false;
126
schema_message->set_name(db);
129
125
Do not create database if another thread is holding read lock.
130
126
Wait for global read lock before acquiring LOCK_create_db.
140
136
if (wait_if_global_read_lock(session, 0, 1))
141
// @todo push this lock down into the engine
146
142
pthread_mutex_lock(&LOCK_create_db);
148
/* check directory */
149
char path[FN_REFLEN+16];
151
path_len= build_table_filename(path, sizeof(path), db, "", false);
152
path[path_len-1]= 0; // remove last '/' from path
154
if (mkdir(path, 0777) == -1)
144
// Check to see if it exists already.
145
if (plugin::StorageEngine::doesSchemaExist(schema_message.name()))
158
if (! is_if_not_exists)
160
my_error(ER_DB_CREATE_EXISTS, MYF(0), path);
147
if (not is_if_not_exists)
149
my_error(ER_DB_CREATE_EXISTS, MYF(0), schema_message.name().c_str());
164
154
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
165
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS),
155
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS),
156
schema_message.name().c_str());
167
157
session->my_ok();
172
my_error(ER_CANT_CREATE_DB, MYF(0), path, errno);
177
error_erno= write_schema_file(path, *schema_message);
178
if (error_erno && error_erno != EEXIST)
180
if (rmdir(path) >= 0)
189
replication_services.rawStatement(session, session->query);
190
session->my_ok(result);
160
else if (not plugin::StorageEngine::createSchema(schema_message)) // Try to create it
162
my_error(ER_CANT_CREATE_DB, MYF(0), schema_message.name().c_str(), errno);
167
replication_services.rawStatement(session, session->query);
193
171
pthread_mutex_unlock(&LOCK_create_db);
194
172
start_waiting_global_read_lock(session);