Commit f46e958e authored by unknown's avatar unknown

character_set_server is now updatable

character_set_database was added
Code optimization: reuse more code for all character sets variables


sql/mysqld.cc:
  character_set_server is now updatable
  character_set_database was added
sql/set_var.cc:
  character_set_server is now updatable
  character_set_database was added
sql/set_var.h:
  character_set_server is now updatable
  character_set_database was added
sql/sql_base.cc:
  character_set_server is now updatable
  character_set_database was added
sql/sql_class.cc:
  character_set_server is now updatable
  character_set_database was added
sql/sql_class.h:
  character_set_server is now updatable
  character_set_database was added
sql/sql_db.cc:
  character_set_server is now updatable
  character_set_database was added
sql/sql_load.cc:
  character_set_server is now updatable
  character_set_database was added
sql/sql_table.cc:
  character_set_server is now updatable
  character_set_database was added
sql/sql_yacc.yy:
  character_set_server is now updatable
  character_set_database was added
BitKeeper/etc/ignore:
  Added scripts/mysql_create_system_tables to the ignore list
parent 69e084af
......@@ -617,3 +617,4 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
include/readline/*.h
scripts/mysql_create_system_tables
......@@ -300,7 +300,7 @@ char* log_error_file_ptr= log_error_file;
char mysql_real_data_home[FN_REFLEN],
language[LIBLEN],reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
max_sort_char,*mysqld_user,*mysqld_chroot, *opt_init_file;
char *language_ptr, *default_collation_name;
char *language_ptr, *default_collation_name, *default_character_set_name;
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION;
char *mysql_unix_port, *opt_mysql_tmpdir;
......@@ -2028,7 +2028,7 @@ static int init_common_variables(const char *conf_file_name, int argc,
#ifdef USE_REGEX
regex_init(&my_charset_latin1);
#endif
if (!(default_charset_info= get_charset_by_csname(sys_charset.value,
if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
MY_CS_PRIMARY,
MYF(MY_WME))))
return 1;
......@@ -2046,6 +2046,8 @@ static int init_common_variables(const char *conf_file_name, int argc,
}
default_charset_info= default_collation;
}
global_system_variables.character_set_server= default_charset_info;
global_system_variables.character_set_database= default_charset_info;
global_system_variables.character_set_results= NULL;
global_system_variables.character_set_client= default_charset_info;
global_system_variables.collation_connection= default_charset_info;
......@@ -3542,8 +3544,8 @@ Disable with --skip-bdb (will save memory)",
0, 0, 0, 0, 0, 0},
#endif /* HAVE_OPENSSL */
{"default-character-set", 'C', "Set the default character set",
(gptr*) &sys_charset.value, (gptr*) &sys_charset.value, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
(gptr*) &default_character_set_name, (gptr*) &default_character_set_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{"default-collation", OPT_DEFAULT_COLLATION, "Set the default collation",
(gptr*) &default_collation_name, (gptr*) &default_collation_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
......@@ -4538,7 +4540,7 @@ static void use_help(void)
static void usage(void)
{
if (!(default_charset_info= get_charset_by_csname(sys_charset.value,
if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
MY_CS_PRIMARY,
MYF(MY_WME))))
exit(1);
......@@ -4642,7 +4644,6 @@ static void mysql_init_variables(void)
pidfile_name_ptr= pidfile_name;
log_error_file_ptr= log_error_file;
language_ptr= language;
default_collation_name= (char*) MYSQL_DEFAULT_COLLATION_NAME;
mysql_data_home= mysql_real_data_home;
thd_startup_options= (OPTION_UPDATE_LOG | OPTION_AUTO_IS_NULL |
OPTION_BIN_LOG | OPTION_QUOTE_SHOW_CREATE);
......@@ -4681,10 +4682,13 @@ static void mysql_init_variables(void)
/* Variables in libraries */
charsets_dir= 0;
sys_charset.value= (char*) MYSQL_DEFAULT_CHARSET_NAME;
default_character_set_name= (char*) MYSQL_DEFAULT_CHARSET_NAME;
default_collation_name= (char*) MYSQL_DEFAULT_COLLATION_NAME;
sys_charset_system.value= (char*) system_charset_info->csname;
/* Set default values for some option variables */
global_system_variables.character_set_server= default_charset_info;
global_system_variables.character_set_database= default_charset_info;
global_system_variables.character_set_results= NULL;
global_system_variables.character_set_client= default_charset_info;
global_system_variables.collation_connection= default_charset_info;
......
......@@ -103,14 +103,12 @@ sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size",
&binlog_cache_size);
sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size",
&SV::bulk_insert_buff_size);
sys_var_str sys_charset("character_set_server",
sys_check_charset,
sys_update_charset,
sys_set_default_charset);
sys_var_character_set_server sys_character_set_server("character_set_server");
sys_var_str sys_charset_system("character_set_system",
sys_check_charset,
sys_update_charset,
sys_set_default_charset);
sys_var_character_set_database sys_character_set_database("character_set_database");
sys_var_character_set_client sys_character_set_client("character_set_client");
sys_var_character_set_results sys_character_set_results("character_set_results");
sys_var_collation_connection sys_collation_connection("collation_connection");
......@@ -362,6 +360,8 @@ sys_var *sys_variables[]=
&sys_binlog_cache_size,
&sys_buffer_results,
&sys_bulk_insert_buff_size,
&sys_character_set_server,
&sys_character_set_database,
&sys_character_set_client,
&sys_character_set_results,
&sys_collation_connection,
......@@ -481,8 +481,9 @@ struct show_var_st init_vars[]= {
#endif
{sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size, SHOW_SYS},
{sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS},
{sys_charset.name, (char*) &sys_charset, SHOW_SYS},
{sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS},
{sys_charset_system.name, (char*) &sys_charset_system, SHOW_SYS},
{sys_character_set_database.name, (char*) &sys_character_set_database,SHOW_SYS},
{sys_character_set_client.name,(char*) &sys_character_set_client,SHOW_SYS},
{sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS},
{sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS},
......@@ -1288,23 +1289,28 @@ bool sys_var_character_set::check(THD *thd, set_var *var)
return 0;
}
bool sys_var_character_set_client::update(THD *thd, set_var *var)
bool sys_var_character_set::update(THD *thd, set_var *var)
{
if (var->type == OPT_GLOBAL)
global_system_variables.character_set_client= var->save_result.charset;
else
thd->variables.character_set_client= var->save_result.charset;
ci_ptr(thd,var->type)[0]= var->save_result.charset;
return 0;
}
byte *sys_var_character_set_client::value_ptr(THD *thd, enum_var_type type)
byte *sys_var_character_set::value_ptr(THD *thd, enum_var_type type)
{
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
global_system_variables.character_set_client :
thd->variables.character_set_client);
CHARSET_INFO *cs= ci_ptr(thd,type)[0];
return cs ? (byte*) cs->csname : (byte*) "NULL";
}
CHARSET_INFO ** sys_var_character_set_client::ci_ptr(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
return &global_system_variables.character_set_client;
else
return &thd->variables.character_set_client;
}
void sys_var_character_set_client::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
......@@ -1313,58 +1319,81 @@ void sys_var_character_set_client::set_default(THD *thd, enum_var_type type)
thd->variables.character_set_client= global_system_variables.character_set_client;
}
CHARSET_INFO ** sys_var_character_set_results::ci_ptr(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
return &global_system_variables.character_set_results;
else
return &thd->variables.character_set_results;
}
bool sys_var_collation_connection::update(THD *thd, set_var *var)
void sys_var_character_set_results::set_default(THD *thd, enum_var_type type)
{
if (var->type == OPT_GLOBAL)
global_system_variables.collation_connection= var->save_result.charset;
if (type == OPT_GLOBAL)
global_system_variables.character_set_results= NULL;
else
thd->variables.collation_connection= var->save_result.charset;
return 0;
thd->variables.character_set_results= global_system_variables.character_set_results;
}
byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type)
CHARSET_INFO ** sys_var_character_set_server::ci_ptr(THD *thd, enum_var_type type)
{
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
global_system_variables.collation_connection :
thd->variables.collation_connection);
return cs ? (byte*) cs->name : (byte*) "NULL";
if (type == OPT_GLOBAL)
return &global_system_variables.character_set_server;
else
return &thd->variables.character_set_server;
}
void sys_var_collation_connection::set_default(THD *thd, enum_var_type type)
void sys_var_character_set_server::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
global_system_variables.collation_connection= default_charset_info;
global_system_variables.character_set_server= default_charset_info;
else
thd->variables.collation_connection= global_system_variables.collation_connection;
thd->variables.character_set_server= global_system_variables.character_set_server;
}
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
return &global_system_variables.character_set_database;
else
return &thd->variables.character_set_database;
}
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
global_system_variables.character_set_database= default_charset_info;
else
thd->variables.character_set_database= thd->db_charset;
}
bool sys_var_character_set_results::update(THD *thd, set_var *var)
bool sys_var_collation_connection::update(THD *thd, set_var *var)
{
if (var->type == OPT_GLOBAL)
global_system_variables.character_set_results= var->save_result.charset;
global_system_variables.collation_connection= var->save_result.charset;
else
thd->variables.character_set_results= var->save_result.charset;
thd->variables.collation_connection= var->save_result.charset;
return 0;
}
byte *sys_var_character_set_results::value_ptr(THD *thd, enum_var_type type)
byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type)
{
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
global_system_variables.character_set_results :
thd->variables.character_set_results);
return cs ? (byte*) cs->csname : (byte*) "NULL";
global_system_variables.collation_connection :
thd->variables.collation_connection);
return cs ? (byte*) cs->name : (byte*) "NULL";
}
void sys_var_character_set_results::set_default(THD *thd, enum_var_type type)
void sys_var_collation_connection::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
global_system_variables.character_set_results= NULL;
global_system_variables.collation_connection= default_charset_info;
else
thd->variables.character_set_results= global_system_variables.character_set_results;
thd->variables.collation_connection= global_system_variables.collation_connection;
}
/*****************************************************************************
Functions to handle SET NAMES and SET CHARACTER SET
*****************************************************************************/
......
......@@ -441,7 +441,10 @@ SHOW_TYPE type() { return SHOW_CHAR; }
return type != STRING_RESULT; /* Only accept strings */
}
bool check_default(enum_var_type type) { return 0; }
bool update(THD *thd, set_var *var);
byte *value_ptr(THD *thd, enum_var_type type);
virtual void set_default(THD *thd, enum_var_type type)= 0;
virtual CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type)= 0;
};
class sys_var_character_set_client :public sys_var_character_set
......@@ -449,9 +452,8 @@ class sys_var_character_set_client :public sys_var_character_set
public:
sys_var_character_set_client(const char *name_arg) :
sys_var_character_set(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);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
class sys_var_character_set_results :public sys_var_character_set
......@@ -459,9 +461,26 @@ class sys_var_character_set_results :public sys_var_character_set
public:
sys_var_character_set_results(const char *name_arg) :
sys_var_character_set(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);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
class sys_var_character_set_server :public sys_var_character_set
{
public:
sys_var_character_set_server(const char *name_arg) :
sys_var_character_set(name_arg) {}
void set_default(THD *thd, enum_var_type type);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
class sys_var_character_set_database :public sys_var_character_set
{
public:
sys_var_character_set_database(const char *name_arg) :
sys_var_character_set(name_arg) {}
void set_default(THD *thd, enum_var_type type);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
class sys_var_collation_connection :public sys_var_collation
......@@ -606,6 +625,5 @@ sys_var *find_sys_var(const char *str, uint length=0);
int sql_set_variables(THD *thd, List<set_var_base> *var_list);
void fix_delay_key_write(THD *thd, enum_var_type type);
extern sys_var_str sys_charset;
extern sys_var_str sys_charset_system;
CHARSET_INFO *get_old_charset_by_name(const char *old_name);
......@@ -2311,7 +2311,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
DBUG_ENTER("mysql_create_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.table_charset= thd->db_charset;
create_info.table_charset= thd->variables.character_set_database;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0, FALSE,
......@@ -2328,7 +2328,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
DBUG_ENTER("mysql_drop_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.table_charset= thd->db_charset;
create_info.table_charset= thd->variables.character_set_database;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0, FALSE,
......
......@@ -109,7 +109,7 @@ THD::THD():user_time(0), is_fatal_error(0),
file_id = 0;
cond_count=0;
warn_id= 0;
db_charset=default_charset_info;
db_charset= global_system_variables.character_set_database;
mysys_var=0;
#ifndef DBUG_OFF
dbug_sentry=THD_SENTRY_MAGIC;
......
......@@ -386,6 +386,8 @@ struct system_variables
my_bool low_priority_updates;
my_bool new_mode;
CHARSET_INFO *character_set_server;
CHARSET_INFO *character_set_database;
CHARSET_INFO *character_set_client;
CHARSET_INFO *character_set_results;
CHARSET_INFO *collation_connection;
......
......@@ -51,7 +51,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
1 Could not create file or write to it. Error sent through my_error()
*/
static bool write_db_opt(const char *path, HA_CREATE_INFO *create)
static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
{
register File file;
char buf[256]; // Should be enough for one option
......@@ -61,8 +61,9 @@ static bool write_db_opt(const char *path, HA_CREATE_INFO *create)
{
ulong length;
CHARSET_INFO *cs= (create && create->table_charset) ?
create->table_charset : default_charset_info;
length= my_sprintf(buf,(buf, "default-character-set=%s\n", cs->name));
create->table_charset :
thd->variables.character_set_database;
length= my_sprintf(buf,(buf, "default-character-set=%s\ndefault-collation=%s\n", cs->csname,cs->name));
/* Error is written by my_write */
if (!my_write(file,(byte*) buf, length, MYF(MY_NABP+MY_WME)))
......@@ -89,7 +90,7 @@ static bool write_db_opt(const char *path, HA_CREATE_INFO *create)
*/
static bool load_db_opt(const char *path, HA_CREATE_INFO *create)
static bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
{
File file;
char buf[256];
......@@ -98,7 +99,7 @@ static bool load_db_opt(const char *path, HA_CREATE_INFO *create)
uint nbytes;
bzero((char*) create,sizeof(*create));
create->table_charset= default_charset_info;
create->table_charset= global_system_variables.character_set_database;
if ((file=my_open(path, O_RDONLY | O_SHARE, MYF(0))) >= 0)
{
IO_CACHE cache;
......@@ -115,7 +116,14 @@ static bool load_db_opt(const char *path, HA_CREATE_INFO *create)
{
if (!strncmp(buf,"default-character-set", (pos-buf)))
{
if (strcmp(pos+1,"DEFAULT"))
if (!(create->table_charset=get_charset_by_csname(pos+1,
MY_CS_PRIMARY,
MYF(0))))
{
sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1);
}
}
else if (!strncmp(buf,"default-collation", (pos-buf)))
{
if (!(create->table_charset=get_charset_by_name(pos+1, MYF(0))))
{
......@@ -124,7 +132,6 @@ static bool load_db_opt(const char *path, HA_CREATE_INFO *create)
}
}
}
}
error=0;
end_io_cache(&cache);
my_close(file,MYF(0));
......@@ -197,7 +204,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
unpack_dirname(path, path);
strcat(path,MY_DB_OPT_FILE);
if (write_db_opt(path, create_info))
if (write_db_opt(thd, path, create_info))
{
/*
Could not create options file.
......@@ -270,7 +277,7 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
/* Check directory */
(void)sprintf(path,"%s/%s/%s", mysql_data_home, db, MY_DB_OPT_FILE);
fn_format(path, path, "", "", MYF(MY_UNPACK_FILENAME));
if ((error=write_db_opt(path, create_info)))
if ((error=write_db_opt(thd, path, create_info)))
goto exit;
/*
......@@ -280,7 +287,9 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
if (thd->db && !strcmp(thd->db,db))
{
thd->db_charset= (create_info && create_info->table_charset) ?
create_info->table_charset : default_charset_info;
create_info->table_charset :
global_system_variables.character_set_database;
thd->variables.character_set_database= thd->db_charset;
}
mysql_update_log.write(thd,thd->query, thd->query_length);
......@@ -615,8 +624,11 @@ bool mysql_change_db(THD *thd, const char *name)
thd->db_access=db_access;
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;
load_db_opt(thd, path, &create);
thd->db_charset= create.table_charset ?
create.table_charset :
global_system_variables.character_set_database;
thd->variables.character_set_database= thd->db_charset;
DBUG_RETURN(0);
}
......@@ -674,7 +686,7 @@ int mysqld_show_create_db(THD *thd, char *dbname,
if (found_libchar)
path[length-1]= FN_LIBCHAR;
strmov(path+length, MY_DB_OPT_FILE);
load_db_opt(path, &create);
load_db_opt(thd, path, &create);
List<Item> field_list;
field_list.push_back(new Item_empty_string("Database",NAME_LEN));
......
......@@ -215,7 +215,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
info.handle_duplicates=handle_duplicates;
info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
READ_INFO read_info(file,tot_length,thd->db_charset,
READ_INFO read_info(file,tot_length,thd->variables.character_set_database,
*field_term,*ex->line_start, *ex->line_term, *enclosed,
info.escape_char, read_file_from_client, is_fifo);
if (read_info.error)
......
......@@ -481,7 +481,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
if (!sql_field->charset)
sql_field->charset = create_info->table_charset ?
create_info->table_charset : thd->db_charset;
create_info->table_charset :
thd->variables.character_set_database;
switch (sql_field->sql_type) {
case FIELD_TYPE_BLOB:
......
......@@ -848,7 +848,7 @@ create:
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.options=$2 | $4;
lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
lex->create_info.table_charset= thd->db_charset;
lex->create_info.table_charset= thd->variables.character_set_database;
lex->name=0;
}
create2
......@@ -1536,7 +1536,7 @@ alter:
lex->select_lex.db=lex->name=0;
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.db_type= DB_TYPE_DEFAULT;
lex->create_info.table_charset= thd->db_charset;
lex->create_info.table_charset= thd->variables.character_set_database;
lex->create_info.row_type= ROW_TYPE_NOT_USED;
lex->alter_keys_onoff=LEAVE_AS_IS;
lex->simple_alter=1;
......@@ -4439,7 +4439,7 @@ option_value:
THD *thd= YYTHD;
LEX *lex= Lex;
$2= $2 ? $2: global_system_variables.character_set_client;
lex->var_list.push_back(new set_var_collation_client($2,thd->db_charset,$2));
lex->var_list.push_back(new set_var_collation_client($2,thd->variables.character_set_database,$2));
}
| NAMES_SYM charset_name_or_default opt_collate
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment