MCPcopy Create free account
hub / github.com/MariaDB/server / load_db_opt

Function load_db_opt

sql/sql_db.cc:544–640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542*/
543
544int load_db_opt(THD *thd, const char *path, Schema_specification_st *create)
545{
546 File file;
547 char buf[256+DATABASE_COMMENT_MAXLEN];
548 DBUG_ENTER("load_db_opt");
549 int error= 0;
550 size_t nbytes;
551 myf utf8_flag= thd->get_utf8_flag();
552
553 bzero((char*) create,sizeof(*create));
554
555 /* Check if options for this database are already in the hash */
556 if (!get_dbopt(thd, path, create))
557 {
558 if (!create->default_table_charset)
559 error= -1; // db.opt did not exists
560 goto err1;
561 }
562
563 /* Otherwise, load options from the .opt file */
564 if ((file= mysql_file_open(key_file_dbopt,
565 path, O_RDONLY | O_SHARE, MYF(0))) < 0)
566 {
567 /*
568 Create an empty entry, to avoid doing an extra file open for every create
569 table.
570 */
571 put_dbopt(path, create);
572 error= -1;
573 goto err1;
574 }
575
576 IO_CACHE cache;
577 if (init_io_cache(&cache, file, IO_SIZE, READ_CACHE, 0, 0, MYF(0)))
578 {
579 error= 1;
580 goto err2; // Not cached
581 }
582
583 while ((int) (nbytes= my_b_gets(&cache, (char*) buf, sizeof(buf))) > 0)
584 {
585 char *pos= buf+nbytes-1;
586 /* Remove end space and control characters */
587 while (pos > buf && !my_isgraph(&my_charset_latin1, pos[-1]))
588 pos--;
589 *pos=0;
590 if ((pos= strchr(buf, '=')))
591 {
592 if (!strncmp(buf,"default-character-set", (pos-buf)))
593 {
594 /*
595 Try character set name, and if it fails
596 try collation name, probably it's an old
597 4.1.0 db.opt file, which didn't have
598 separate default-character-set and
599 default-collation commands.
600 */
601 if (!(create->default_table_charset=

Callers 3

write_db_optFunction · 0.85
load_db_opt_by_nameFunction · 0.85
mysql_upgrade_dbFunction · 0.85

Calls 10

get_dboptFunction · 0.85
put_dboptFunction · 0.85
init_io_cacheFunction · 0.85
my_b_getsFunction · 0.85
get_charset_by_csnameFunction · 0.85
get_charset_by_nameFunction · 0.85
end_io_cacheFunction · 0.85
get_utf8_flagMethod · 0.80
make_clex_stringMethod · 0.80
sql_print_errorFunction · 0.70

Tested by

no test coverage detected