diff options
author | unknown <anozdrin/alik@ibm.> | 2007-06-14 19:23:55 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@ibm.> | 2007-06-14 19:23:55 +0400 |
commit | 83de46bcf71f05580cf664f02569290a8fa214dd (patch) | |
tree | b54dd9543e107094f780c4a99b8dde4aa0213024 /sql/sql_db.cc | |
parent | c7aeb8f37b007dfdd4d5339a7dd4b0083282be4e (diff) | |
download | mariadb-git-83de46bcf71f05580cf664f02569290a8fa214dd.tar.gz |
This the 4-th patch in scope of CS patch (BUG#11986).
The patch contains the following changes:
- Introduce auxilary functions to convenient work with character sets:
- resolve_charset();
- resolve_collation();
- get_default_db_collation();
- Introduce lex_string_set();
- Refactor Table_trigger_list::process_triggers() &
sp_head::execute_trigger() to be consistent with other code;
- Move reusable code from add_table_for_trigger() into
build_trn_path(), check_trn_exists() and load_table_name_for_trigger()
to be used in the following patch.
- Rename triggers_file_ext and trigname_file_ext into TRN_EXT and
TRG_EXT respectively.
include/my_sys.h:
Introduced auxilary functions (to be used in the following patch).
mysys/charset.c:
Introduced auxilary functions (to be used in the following patch).
sql/handler.cc:
Rename triggers_file_ext -> TRG_EXT;
Rename trigname_file_ext -> TRN_EXT.
sql/mysql_priv.h:
1. Fix typo;
2. Introduce auxilary functions (set_lex_string() will be used
in the following patch);
3. Rename triggers_file_ext -> TRG_EXT;
Rename trigname_file_ext -> TRN_EXT.
sql/sp_head.cc:
Make sp_head::execute_trigger() consistent with
sp_head::execute_function() and sp_head::execute_procedure().
sql/sp_head.h:
Make sp_head::execute_trigger() consistent with
sp_head::execute_function() and sp_head::execute_procedure().
sql/sql_db.cc:
1. Introduce auxilary function.
2. Polishing.
sql/sql_trigger.cc:
1. Move common code from add_table_for_trigger() into
- build_trn_path();
- check_trn_exists();
- load_table_name_for_trigger();
2. Polishing.
sql/sql_trigger.h:
1. Move common code from add_table_for_trigger() into
- build_trn_path();
- check_trn_exists();
- load_table_name_for_trigger();
2. Polishing.
Diffstat (limited to 'sql/sql_db.cc')
-rw-r--r-- | sql/sql_db.cc | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 82938184245..43d84740f0b 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -538,6 +538,37 @@ bool load_db_opt_by_name(THD *thd, const char *db_name, } +/** + Return default database collation. + + @param thd Thread context. + @param db_name Database name. + + @return CHARSET_INFO object. The operation always return valid character + set, even if the database does not exist. +*/ + +CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name) +{ + HA_CREATE_INFO db_info; + + if (thd->db != NULL && strcmp(db_name, thd->db) == 0) + return thd->db_charset; + + load_db_opt_by_name(thd, db_name, &db_info); + + /* + NOTE: even if load_db_opt_by_name() fails, + db_info.default_table_charset contains valid character set + (collation_server). We should not fail if load_db_opt_by_name() fails, + because it is valid case. If a database has been created just by + "mkdir", it does not contain db.opt file, but it is valid database. + */ + + return db_info.default_table_charset; +} + + /* Create a database @@ -751,10 +782,8 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) if ((error=write_db_opt(thd, path, create_info))) goto exit; - /* - Change options if current database is being altered - TODO: Delete this code - */ + /* Change options if current database is being altered. */ + if (thd->db && !strcmp(thd->db,db)) { thd->db_charset= create_info->default_table_charset ? @@ -1358,6 +1387,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch) Security_context *sctx= thd->security_ctx; ulong db_access= sctx->db_access; + CHARSET_INFO *db_default_cl; DBUG_ENTER("mysql_change_db"); DBUG_PRINT("enter",("name: '%s'", new_db_name->str)); @@ -1487,16 +1517,9 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch) attributes and will be freed in THD::~THD(). */ - { - HA_CREATE_INFO db_options; + db_default_cl= get_default_db_collation(thd, new_db_file_name.str); - load_db_opt_by_name(thd, new_db_name->str, &db_options); - - mysql_change_db_impl(thd, &new_db_file_name, db_access, - db_options.default_table_charset ? - db_options.default_table_charset : - thd->variables.collation_server); - } + mysql_change_db_impl(thd, &new_db_file_name, db_access, db_default_cl); DBUG_RETURN(FALSE); } |