327
330
1 Could not create file or write to it. Error sent through my_error()
330
static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
333
static bool write_db_opt(THD *thd, const char *path, const char *name, HA_CREATE_INFO *create)
333
char buf[256]; // Should be enough for one option
334
335
bool error= true;
336
340
if (!create->default_table_charset)
337
341
create->default_table_charset= thd->variables.collation_server;
339
343
if (put_dbopt(path, create))
342
if ((file=my_create(path, CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
345
length= (uint32_t) (strxnmov(buf, sizeof(buf)-1, "default-character-set=",
346
create->default_table_charset->csname,
347
"\ndefault-collation=",
348
create->default_table_charset->name,
351
/* Error is written by my_write */
352
if (!my_write(file,(uchar*) buf, length, MYF(MY_NABP+MY_WME)))
354
my_close(file,MYF(0));
347
db.set_characterset(create->default_table_charset->csname);
348
db.set_collation(create->default_table_charset->name);
350
fstream output(path, ios::out | ios::trunc | ios::binary);
351
if (!db.SerializeToOstream(&output))
386
383
if (!get_dbopt(path, create))
389
/* Otherwise, load options from the .opt file */
390
if ((file=my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
394
if (init_io_cache(&cache, file, IO_SIZE, READ_CACHE, 0, 0, MYF(0)))
397
while ((int) (nbytes= my_b_gets(&cache, (char*) buf, sizeof(buf))) > 0)
399
char *pos= buf+nbytes-1;
400
/* Remove end space and control characters */
401
while (pos > buf && !my_isgraph(&my_charset_latin1, pos[-1]))
404
if ((pos= strchr(buf, '=')))
406
if (!strncmp(buf,"default-character-set", (pos-buf)))
409
Try character set name, and if it fails
410
try collation name, probably it's an old
411
4.1.0 db.opt file, which didn't have
412
separate default-character-set and
413
default-collation commands.
415
if (!(create->default_table_charset=
416
get_charset_by_csname(pos+1, MY_CS_PRIMARY, MYF(0))) &&
417
!(create->default_table_charset=
418
get_charset_by_name(pos+1, MYF(0))))
420
sql_print_error("Error while loading database options: '%s':",path);
421
sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1);
422
create->default_table_charset= default_charset_info;
425
else if (!strncmp(buf,"default-collation", (pos-buf)))
427
if (!(create->default_table_charset= get_charset_by_name(pos+1,
430
sql_print_error("Error while loading database options: '%s':",path);
431
sql_print_error(ER(ER_UNKNOWN_COLLATION),pos+1);
432
create->default_table_charset= default_charset_info;
386
fstream input(path, ios::in | ios::binary);
389
else if (!db.ParseFromIstream(&input))
392
buffer= db.characterset();
393
if (!(create->default_table_charset= get_charset_by_csname(buffer.c_str(), MY_CS_PRIMARY, MYF(0))))
395
sql_print_error("Error while loading database options: '%s':",path);
396
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
397
create->default_table_charset= default_charset_info;
400
buffer= db.collation();
401
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str(), MYF(0))))
403
sql_print_error("Error while loading database options: '%s':",path);
404
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
405
create->default_table_charset= default_charset_info;
438
409
Put the loaded value into the hash.
439
410
Note that another thread could've added the same
626
594
path[path_len-1]= FN_LIBCHAR;
627
595
strmake(path+path_len, MY_DB_OPT_FILE, sizeof(path)-path_len-1);
628
if (write_db_opt(thd, path, create_info))
596
if (write_db_opt(thd, path, db, create_info))
631
599
Could not create options file.
735
703
"table name to file name" encoding.
737
705
build_table_filename(path, sizeof(path), db, "", MY_DB_OPT_FILE, 0);
738
if ((error=write_db_opt(thd, path, create_info)))
706
if ((error=write_db_opt(thd, path, db, create_info)))
741
709
/* Change options if current database is being altered. */