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

Function write_db_opt

sql/sql_db.cc:464–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462*/
463
464static bool write_db_opt(THD *thd, const char *path,
465 Schema_specification_st *create)
466{
467 File file;
468 char buf[256+DATABASE_COMMENT_MAXLEN];
469 bool error=1;
470
471 if (create->schema_comment)
472 {
473 if (validate_comment_length(thd, create->schema_comment,
474 DATABASE_COMMENT_MAXLEN,
475 ER_TOO_LONG_DATABASE_COMMENT,
476 thd->lex->name.str))
477 return error;
478 }
479
480 if (thd->lex->sql_command == SQLCOM_ALTER_DB &&
481 (!create->schema_comment || !create->default_table_charset))
482 {
483 /* Use existing values of schema_comment and charset for
484 ALTER DATABASE queries */
485 Schema_specification_st tmp;
486 tmp.init();
487 load_db_opt(thd, path, &tmp);
488
489 if (!create->schema_comment)
490 create->schema_comment= tmp.schema_comment;
491
492 if (!create->default_table_charset)
493 create->default_table_charset= tmp.default_table_charset;
494 }
495
496 if (!create->default_table_charset)
497 create->default_table_charset= thd->variables.collation_server;
498
499 if (put_dbopt(path, create))
500 return 1;
501
502 if ((file= mysql_file_create(key_file_dbopt, path, CREATE_MODE,
503 O_RDWR | O_TRUNC, MYF(MY_WME))) >= 0)
504 {
505 ulong length;
506 length= (ulong) (strxnmov(buf, sizeof(buf)-1, "default-character-set=",
507 create->default_table_charset->cs_name.str,
508 "\ndefault-collation=",
509 create->default_table_charset->coll_name.str,
510 "\n", NullS) - buf);
511
512 if (create->schema_comment)
513 length= (ulong) (strxnmov(buf+length, sizeof(buf)-1-length,
514 "comment=", create->schema_comment->str,
515 "\n", NullS) - buf);
516
517 /* Error is written by mysql_file_write */
518 if (!mysql_file_write(file, (uchar*) buf, length, MYF(MY_NABP+MY_WME)))
519 error=0;
520 mysql_file_close(file, MYF(0));
521 }

Callers 2

mysql_create_db_internalFunction · 0.85
mysql_alter_db_internalFunction · 0.85

Calls 5

validate_comment_lengthFunction · 0.85
load_db_optFunction · 0.85
put_dboptFunction · 0.85
strxnmovFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected