166
166
(collation_server).
169
load_db_opt_by_name(session, db_name, &db_info);
169
171
return db_info.default_table_charset;
174
/* path is path to database, not schema file */
175
static int write_schema_file(Session *session,
176
const char *path, const char *name,
177
HA_CREATE_INFO *create)
180
char schema_file_tmp[FN_REFLEN];
181
string schema_file(path);
187
snprintf(schema_file_tmp, FN_REFLEN, "%s%cdb.opt.tmpXXXXXX",path,FN_LIBCHAR);
189
schema_file.append(1, FN_LIBCHAR);
190
schema_file.append("db.opt");
192
int fd= mkstemp(schema_file_tmp);
197
if (!create->default_table_charset)
198
create->default_table_charset= session->variables.collation_server;
201
db.set_collation(create->default_table_charset->name);
203
if (!db.SerializeToFileDescriptor(fd))
206
unlink(schema_file_tmp);
210
if (rename(schema_file_tmp, schema_file.c_str()) == -1)
220
int load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create)
225
memset(create, 0, sizeof(*create));
226
create->default_table_charset= session->variables.collation_server;
228
int fd= open(path, O_RDONLY);
233
if (!db.ParseFromFileDescriptor(fd))
240
buffer= db.collation();
241
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str(),
244
errmsg_printf(ERRMSG_LVL_ERROR,
245
_("Error while loading database options: '%s':"),path);
246
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
247
create->default_table_charset= default_charset_info;
254
int load_db_opt_by_name(Session *session, const char *db_name,
255
HA_CREATE_INFO *db_create_info)
257
char db_opt_path[FN_REFLEN];
260
Pass an empty file name, and the database options file name as extension
261
to avoid table name to file name encoding.
263
(void) build_table_filename(db_opt_path, sizeof(db_opt_path),
264
db_name, "", "db.opt", 0);
266
return load_db_opt(session, db_opt_path, db_create_info);
174
271
Create a database
235
331
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
236
332
path[path_len-1]= 0; // Remove last '/' from path
238
if (!stat(path,&stat_info))
334
if (mkdir(path,0777) == -1)
240
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
242
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
338
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
340
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
344
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
345
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db);
246
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
247
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db);
352
my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno);
357
error= write_schema_file(session, path, db, create_info);
358
if (error && error != EEXIST)
257
my_error(EE_STAT, MYF(0), path, errno);
260
if (mkdir(path,0777) < 0)
262
my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno);
360
if (rmdir(path) >= 0)
318
419
pthread_mutex_lock(&LOCK_drizzle_create_db);
320
421
/* Change options if current database is being altered. */
422
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
423
path[path_len-1]= 0; // Remove last '/' from path
425
error= write_schema_file(session, path, db, create_info);
426
if (error && error != EEXIST)
428
/* TODO: find some witty way of getting back an error message */
429
pthread_mutex_unlock(&LOCK_drizzle_create_db);
322
433
if (session->db && !strcmp(session->db,db))
390
501
pthread_mutex_lock(&LOCK_drizzle_create_db);
392
503
length= build_table_filename(path, sizeof(path), db, "", "", 0);
504
strcpy(path+length, "db.opt"); // Append db option file name
393
506
path[length]= '\0'; // Remove file name
395
508
/* See if the directory exists */