| 462 | */ |
| 463 | |
| 464 | static 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 | } |
no test coverage detected