30
36
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
31
37
const char *db, const char *path, uint level,
32
TABLE_LIST **dropped_tables);
38
TableList **dropped_tables);
34
40
static bool rm_dir_w_symlink(const char *org_path, bool send_error);
35
41
static void mysql_change_db_impl(THD *thd,
36
42
LEX_STRING *new_db_name,
37
CHARSET_INFO *new_db_charset);
43
const CHARSET_INFO * const new_db_charset);
40
46
/* Database lock hash */
337
344
if (put_dbopt(path, create))
340
if ((file=my_create(path, CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
343
length= (ulong) (strxnmov(buf, sizeof(buf)-1, "default-character-set=",
344
create->default_table_charset->csname,
345
"\ndefault-collation=",
346
create->default_table_charset->name,
349
/* Error is written by my_write */
350
if (!my_write(file,(uchar*) buf, length, MYF(MY_NABP+MY_WME)))
352
my_close(file,MYF(0));
348
db.set_characterset(create->default_table_charset->csname);
349
db.set_collation(create->default_table_charset->name);
351
fstream output(path, ios::out | ios::trunc | ios::binary);
352
if (!db.SerializeToOstream(&output))
373
374
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
380
memset((char*) create, 0, sizeof(*create));
380
memset(create, 0, sizeof(*create));
381
381
create->default_table_charset= thd->variables.collation_server;
383
383
/* Check if options for this database are already in the hash */
384
384
if (!get_dbopt(path, create))
387
/* Otherwise, load options from the .opt file */
388
if ((file=my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
392
if (init_io_cache(&cache, file, IO_SIZE, READ_CACHE, 0, 0, MYF(0)))
395
while ((int) (nbytes= my_b_gets(&cache, (char*) buf, sizeof(buf))) > 0)
397
char *pos= buf+nbytes-1;
398
/* Remove end space and control characters */
399
while (pos > buf && !my_isgraph(&my_charset_latin1, pos[-1]))
402
if ((pos= strchr(buf, '=')))
404
if (!strncmp(buf,"default-character-set", (pos-buf)))
407
Try character set name, and if it fails
408
try collation name, probably it's an old
409
4.1.0 db.opt file, which didn't have
410
separate default-character-set and
411
default-collation commands.
413
if (!(create->default_table_charset=
414
get_charset_by_csname(pos+1, MY_CS_PRIMARY, MYF(0))) &&
415
!(create->default_table_charset=
416
get_charset_by_name(pos+1, MYF(0))))
418
sql_print_error("Error while loading database options: '%s':",path);
419
sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1);
420
create->default_table_charset= default_charset_info;
423
else if (!strncmp(buf,"default-collation", (pos-buf)))
425
if (!(create->default_table_charset= get_charset_by_name(pos+1,
428
sql_print_error("Error while loading database options: '%s':",path);
429
sql_print_error(ER(ER_UNKNOWN_COLLATION),pos+1);
430
create->default_table_charset= default_charset_info;
387
fstream input(path, ios::in | ios::binary);
390
else if (!db.ParseFromIstream(&input))
393
buffer= db.characterset();
394
if (!(create->default_table_charset= get_charset_by_csname(buffer.c_str(), MY_CS_PRIMARY, MYF(0))))
396
sql_print_error(_("Error while loading database options: '%s':"),path);
397
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
398
create->default_table_charset= default_charset_info;
401
buffer= db.collation();
402
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str(), MYF(0))))
404
sql_print_error(_("Error while loading database options: '%s':"),path);
405
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
406
create->default_table_charset= default_charset_info;
436
410
Put the loaded value into the hash.
437
411
Note that another thread could've added the same
904
875
thd->clear_error();
905
876
thd->server_status|= SERVER_STATUS_DB_DROPPED;
906
my_ok(thd, (ulong) deleted);
877
my_ok(thd, (uint32_t) deleted);
907
878
thd->server_status&= ~SERVER_STATUS_DB_DROPPED;
909
880
else if (mysql_bin_log.is_open())
911
882
char *query, *query_pos, *query_end, *query_data_start;
915
886
if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN)))
916
887
goto exit; /* not much else we can do */
917
query_pos= query_data_start= strmov(query,"drop table ");
888
query_pos= query_data_start= stpcpy(query,"drop table ");
918
889
query_end= query + MAX_DROP_TABLE_Q_LEN;
919
890
db_len= strlen(db);
967
938
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
968
939
const char *org_path, uint level,
969
TABLE_LIST **dropped_tables)
940
TableList **dropped_tables)
972
ulong found_other_files=0;
943
uint32_t found_other_files=0;
973
944
char filePath[FN_REFLEN];
974
TABLE_LIST *tot_list=0, **tot_list_next;
945
TableList *tot_list=0, **tot_list_next;
976
947
tot_list_next= &tot_list;