diff options
author | unknown <bar@bar.mysql.r18.ru> | 2003-04-07 16:10:27 +0500 |
---|---|---|
committer | unknown <bar@bar.mysql.r18.ru> | 2003-04-07 16:10:27 +0500 |
commit | b9b15d52393f9aa33fbb6a6fdc40c8df75aadb81 (patch) | |
tree | d46595aeafebe373e34fab33628294f37eef348d /sql | |
parent | 65ae25d092fe138ab0d0f9039a3ef8bc610b5031 (diff) | |
download | mariadb-git-b9b15d52393f9aa33fbb6a6fdc40c8df75aadb81.tar.gz |
sys_var_collation is now abstract class
Two separate classes sys_var_client_collation and sys_var_literal_collation have been added
for "literal_collation" and "client_collation" variables.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/protocol.cc | 4 | ||||
-rw-r--r-- | sql/set_var.cc | 114 | ||||
-rw-r--r-- | sql/set_var.h | 28 | ||||
-rw-r--r-- | sql/sql_analyse.cc | 8 | ||||
-rw-r--r-- | sql/sql_class.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.h | 7 | ||||
-rw-r--r-- | sql/sql_db.cc | 2 | ||||
-rw-r--r-- | sql/sql_lex.cc | 5 | ||||
-rw-r--r-- | sql/sql_lex.h | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 |
11 files changed, 113 insertions, 62 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 0a3f453e4b6..a6338630568 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4567,6 +4567,8 @@ static void set_options(void) /* Set default values for some variables */ global_system_variables.convert_result_charset= TRUE; + global_system_variables.client_collation= default_charset_info; + global_system_variables.literal_collation= default_charset_info; global_system_variables.table_type= DB_TYPE_MYISAM; global_system_variables.tx_isolation= ISO_REPEATABLE_READ; global_system_variables.select_limit= (ulonglong) HA_POS_ERROR; diff --git a/sql/protocol.cc b/sql/protocol.cc index f82981bd309..195fec80ed0 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -805,7 +805,7 @@ bool Protocol_simple::store(float from, uint32 decimals, String *buffer) field_types[field_pos] == MYSQL_TYPE_FLOAT); field_pos++; #endif - buffer->set((double) from, decimals, thd->variables.thd_charset); + buffer->set((double) from, decimals, thd->charset()); return net_store_data((char*) buffer->ptr(), buffer->length()); } @@ -817,7 +817,7 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer) field_types[field_pos] == MYSQL_TYPE_DOUBLE); field_pos++; #endif - buffer->set(from, decimals, thd->variables.thd_charset); + buffer->set(from, decimals, thd->charset()); return net_store_data((char*) buffer->ptr(), buffer->length()); } diff --git a/sql/set_var.cc b/sql/set_var.cc index 127988b8c4e..ddebf47a25d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -133,6 +133,7 @@ sys_var_thd_ulong sys_join_buffer_size("join_buffer_size", sys_var_ulonglong_ptr sys_key_buffer_size("key_buffer_size", &keybuff_size, fix_key_buffer_size); +sys_var_literal_collation sys_literal_collation("literal_collation"); sys_var_bool_ptr sys_local_infile("local_infile", &opt_local_infile); sys_var_thd_bool sys_log_warnings("log_warnings", &SV::log_warnings); @@ -363,6 +364,7 @@ sys_var *sys_variables[]= &sys_interactive_timeout, &sys_join_buffer_size, &sys_key_buffer_size, + &sys_literal_collation, &sys_last_insert_id, &sys_local_infile, &sys_log_binlog, @@ -507,6 +509,7 @@ struct show_var_st init_vars[]= { {sys_key_buffer_size.name, (char*) &sys_key_buffer_size, SHOW_SYS}, {"language", language, SHOW_CHAR}, {"large_files_support", (char*) &opt_large_files, SHOW_BOOL}, + {sys_literal_collation.name,(char*) &sys_literal_collation, SHOW_SYS}, {sys_local_infile.name, (char*) &sys_local_infile, SHOW_SYS}, #ifdef HAVE_MLOCKALL {"locked_in_memory", (char*) &locked_in_memory, SHOW_BOOL}, @@ -1155,7 +1158,8 @@ byte *sys_var_thd_bit::value_ptr(THD *thd, enum_var_type type) } -typedef struct old_names_map_st { +typedef struct old_names_map_st +{ const char *old_name; const char *new_name; } my_old_conv; @@ -1187,20 +1191,12 @@ CHARSET_INFO *get_old_charset_by_name(const char *name) return NULL; } -bool sys_var_client_collation::check(THD *thd, set_var *var) +bool sys_var_collation::check(THD *thd, set_var *var) { CHARSET_INFO *tmp; char buff[80]; String str(buff,sizeof(buff), system_charset_info), *res; - if (!var->value) // Default value - { - var->save_result.charset= (var->type != OPT_GLOBAL ? - global_system_variables.thd_charset - : thd->db_charset); - return 0; - } - if (!(res=var->value->val_str(&str))) res= &empty_string; @@ -1217,27 +1213,90 @@ bool sys_var_client_collation::check(THD *thd, set_var *var) bool sys_var_client_collation::update(THD *thd, set_var *var) { if (var->type == OPT_GLOBAL) - global_system_variables.thd_charset= var->save_result.charset; + global_system_variables.client_collation= var->save_result.charset; else { - thd->variables.thd_charset= var->save_result.charset; + thd->variables.client_collation= var->save_result.charset; thd->protocol_simple.init(thd); thd->protocol_prep.init(thd); } return 0; } - byte *sys_var_client_collation::value_ptr(THD *thd, enum_var_type type) { CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? - global_system_variables.thd_charset : - thd->variables.thd_charset); + global_system_variables.client_collation : + thd->variables.client_collation); return cs ? (byte*) cs->name : (byte*) ""; } +void sys_var_client_collation::set_default(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + global_system_variables.client_collation= default_charset_info; + else + { + thd->variables.client_collation= thd->db_charset; + } +} +bool sys_var_literal_collation::update(THD *thd, set_var *var) +{ + if (var->type == OPT_GLOBAL) + global_system_variables.literal_collation= var->save_result.charset; + else + thd->variables.literal_collation= var->save_result.charset; + return 0; +} + +byte *sys_var_literal_collation::value_ptr(THD *thd, enum_var_type type) +{ + CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? + global_system_variables.literal_collation : + thd->variables.literal_collation); + return cs ? (byte*) cs->name : (byte*) ""; +} + +void sys_var_literal_collation::set_default(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + global_system_variables.literal_collation= default_charset_info; + else + thd->variables.literal_collation= thd->db_charset; +} + + +/***************************************************************************** + Functions to handle SET NAMES and SET CHARACTER SET +*****************************************************************************/ + +int set_var_client_collation::check(THD *thd) +{ + client_charset= client_charset ? client_charset : thd->db_charset; + client_collation= client_collation ? client_collation : client_charset; + if (!my_charset_same(client_charset, client_collation)) + { + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + client_collation->name, client_charset->csname); + return -1; + } + return 0; +} + +int set_var_client_collation::update(THD *thd) +{ + thd->variables.client_collation= client_collation; + thd->variables.literal_collation= client_collation; + thd->variables.convert_result_charset= convert_result_charset; + thd->protocol_simple.init(thd); + thd->protocol_prep.init(thd); + return 0; +} + +/****************************************************************************/ + bool sys_var_timestamp::update(THD *thd, set_var *var) { thd->set_time((time_t) var->value->val_int()); @@ -1656,31 +1715,6 @@ int set_var_password::update(THD *thd) } -/***************************************************************************** - Functions to handle SET NAMES and SET CHARACTER SET -*****************************************************************************/ - -int set_var_client_collation::check(THD *thd) -{ - client_charset= client_charset ? client_charset : thd->db_charset; - client_collation= client_collation ? client_collation : client_charset; - if (!my_charset_same(client_charset, client_collation)) - { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - client_collation->name, client_charset->csname); - return -1; - } - return 0; -} - -int set_var_client_collation::update(THD *thd) -{ - thd->variables.thd_charset= client_collation; - thd->variables.convert_result_charset= convert_result_charset; - thd->protocol_simple.init(thd); - thd->protocol_prep.init(thd); - return 0; -} diff --git a/sql/set_var.h b/sql/set_var.h index 7b2f9d5cb80..51f59981e14 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -406,20 +406,36 @@ public: }; -class sys_var_client_collation :public sys_var_thd +class sys_var_collation :public sys_var_thd { public: - sys_var_client_collation(const char *name_arg) :sys_var_thd(name_arg) - {} + sys_var_collation(const char *name_arg) :sys_var_thd(name_arg) {} bool check(THD *thd, set_var *var); - bool update(THD *thd, set_var *var); - SHOW_TYPE type() { return SHOW_CHAR; } - byte *value_ptr(THD *thd, enum_var_type type); +SHOW_TYPE type() { return SHOW_CHAR; } bool check_update_type(Item_result type) { return type != STRING_RESULT; /* Only accept strings */ } bool check_default(enum_var_type type) { return 0; } + virtual void set_default(THD *thd, enum_var_type type)= 0; +}; + +class sys_var_client_collation :public sys_var_collation +{ +public: + sys_var_client_collation(const char *name_arg) :sys_var_collation(name_arg) {} + bool update(THD *thd, set_var *var); + void set_default(THD *thd, enum_var_type type); + byte *value_ptr(THD *thd, enum_var_type type); +}; + +class sys_var_literal_collation :public sys_var_collation +{ +public: + sys_var_literal_collation(const char *name_arg) :sys_var_collation(name_arg) {} + bool update(THD *thd, set_var *var); + void set_default(THD *thd, enum_var_type type); + byte *value_ptr(THD *thd, enum_var_type type); }; diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 9bcfff62ba0..1f5462f8a3b 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -901,14 +901,14 @@ int collect_real(double *element, element_count count __attribute__((unused)), TREE_INFO *info) { char buff[MAX_FIELD_WIDTH]; - String s(buff, sizeof(buff),current_thd->variables.thd_charset); + String s(buff, sizeof(buff),current_thd->charset()); if (info->found) info->str->append(','); else info->found = 1; info->str->append('\''); - s.set(*element, info->item->decimals, current_thd->variables.thd_charset); + s.set(*element, info->item->decimals, current_thd->charset()); info->str->append(s); info->str->append('\''); return 0; @@ -927,7 +927,7 @@ int collect_longlong(longlong *element, else info->found = 1; info->str->append('\''); - s.set(*element, current_thd->variables.thd_charset); + s.set(*element, current_thd->charset()); info->str->append(s); info->str->append('\''); return 0; @@ -946,7 +946,7 @@ int collect_ulonglong(ulonglong *element, else info->found = 1; info->str->append('\''); - s.set(*element, current_thd->variables.thd_charset); + s.set(*element, current_thd->charset()); info->str->append(s); info->str->append('\''); return 0; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 8fd507c2349..31159dc259f 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -207,7 +207,7 @@ void THD::init(void) { pthread_mutex_lock(&LOCK_global_system_variables); variables= global_system_variables; - variables.thd_charset=default_charset_info; + variables.client_collation= default_charset_info; pthread_mutex_unlock(&LOCK_global_system_variables); server_status= SERVER_STATUS_AUTOCOMMIT; options= thd_startup_options; diff --git a/sql/sql_class.h b/sql/sql_class.h index 9a853fc5736..1d4dafb997e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -380,7 +380,8 @@ struct system_variables my_bool new_mode; my_bool convert_result_charset; - CHARSET_INFO *thd_charset; + CHARSET_INFO *client_collation; + CHARSET_INFO *literal_collation; }; void free_tmp_table(THD *thd, TABLE *entry); @@ -661,9 +662,9 @@ public: net.report_error= 1; DBUG_PRINT("error",("Fatal error set")); } - inline CHARSET_INFO *charset() { return variables.thd_charset; } + inline CHARSET_INFO *charset() { return variables.client_collation; } inline CHARSET_INFO *result_charset(CHARSET_INFO *cs) - { return variables.convert_result_charset ? variables.thd_charset : cs; } + { return variables.convert_result_charset ? charset() : cs; } }; /* diff --git a/sql/sql_db.cc b/sql/sql_db.cc index ffa5416eaf5..903fcce6350 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -602,7 +602,7 @@ bool mysql_change_db(THD *thd, const char *name) strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE); load_db_opt(path, &create); thd->db_charset= create.table_charset ? create.table_charset : default_charset_info; - thd->variables.thd_charset=thd->db_charset ? thd->db_charset : default_charset_info; + thd->variables.client_collation=thd->db_charset ? thd->db_charset : default_charset_info; DBUG_RETURN(0); } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 88375b9469b..d5d438fc3a1 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -118,7 +118,6 @@ LEX *lex_start(THD *thd, uchar *buf,uint length) lex->select_lex.ftfunc_list_alloc.empty(); lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc; lex->current_select= &lex->select_lex; - lex->thd_charset= lex->thd->variables.thd_charset; lex->yacc_yyss=lex->yacc_yyvs=0; lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE); lex->sql_command=SQLCOM_END; @@ -209,7 +208,7 @@ static char *get_text(LEX *lex) { reg1 uchar c,sep; uint found_escape=0; - CHARSET_INFO *cs= lex->thd->variables.thd_charset; + CHARSET_INFO *cs= lex->thd->charset(); sep= yyGetLast(); // String should end with this //lex->tok_start=lex->ptr-1; // Remember ' @@ -422,7 +421,7 @@ int yylex(void *arg, void *yythd) enum my_lex_states state,prev_state; LEX *lex= &(((THD *)yythd)->lex); YYSTYPE *yylval=(YYSTYPE*) arg; - CHARSET_INFO *cs= ((THD *) yythd)->variables.thd_charset; + CHARSET_INFO *cs= ((THD *) yythd)->charset(); uchar *state_map= cs->state_map; uchar *ident_map= cs->ident_map; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 046b67816f1..9fb0f8cfdf5 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -448,7 +448,6 @@ typedef struct st_lex TYPELIB *interval; create_field *last_field; Item *default_value, *comment; - CHARSET_INFO *thd_charset; uint uint_geom_type; LEX_USER *grant_user; gptr yacc_yyss,yacc_yyvs; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 07325d9a1b0..a8c02bf86f2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2167,7 +2167,7 @@ simple_expr: | simple_expr COLLATE_SYM ident_or_text %prec NEG { $$= new Item_func_set_collation($1,new Item_string($3.str,$3.length, - YYTHD->variables.thd_charset)); + YYTHD->charset())); } | literal | param_marker |