mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Database default charset now works:
CREATE DATABASE dbname DEFAULT CHARACTERSET=latin1
This commit is contained in:
@ -478,3 +478,4 @@ vio/test-ssl
|
|||||||
vio/test-sslclient
|
vio/test-sslclient
|
||||||
vio/test-sslserver
|
vio/test-sslserver
|
||||||
vio/viotest-ssl
|
vio/viotest-ssl
|
||||||
|
tests/client_test
|
||||||
|
@ -103,6 +103,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
|
|||||||
file_id = 0;
|
file_id = 0;
|
||||||
cond_count=0;
|
cond_count=0;
|
||||||
convert_set=0;
|
convert_set=0;
|
||||||
|
db_charset=default_charset_info;
|
||||||
mysys_var=0;
|
mysys_var=0;
|
||||||
#ifndef DBUG_OFF
|
#ifndef DBUG_OFF
|
||||||
dbug_sentry=THD_SENTRY_MAGIC;
|
dbug_sentry=THD_SENTRY_MAGIC;
|
||||||
|
@ -473,7 +473,8 @@ public:
|
|||||||
ulong slave_proxy_id;
|
ulong slave_proxy_id;
|
||||||
NET* slave_net; // network connection from slave -> m.
|
NET* slave_net; // network connection from slave -> m.
|
||||||
my_off_t log_pos;
|
my_off_t log_pos;
|
||||||
|
CHARSET_INFO *db_charset;
|
||||||
|
|
||||||
THD();
|
THD();
|
||||||
~THD();
|
~THD();
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MY_DB_OPT_FILE ".db.opt"
|
||||||
|
|
||||||
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
|
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
|
||||||
const char *db, const char *path,
|
const char *db, const char *path,
|
||||||
uint level);
|
uint level);
|
||||||
@ -82,12 +84,12 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent
|
|||||||
|
|
||||||
strcat(path,"/");
|
strcat(path,"/");
|
||||||
unpack_dirname(path,path);
|
unpack_dirname(path,path);
|
||||||
strcat(path,"db.opt");
|
strcat(path,MY_DB_OPT_FILE);
|
||||||
if ((file=my_create(path,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
|
if ((file=my_create(path,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
|
||||||
{
|
{
|
||||||
sprintf(path,"CREATE DATABASE %s DEFAULT CHARACTER SET=%s\n",db,
|
sprintf(path,"default-character-set=%s\n",
|
||||||
(create_info && create_info->table_charset)
|
(create_info && create_info->table_charset) ?
|
||||||
? create_info->table_charset->name : "DEFAULT");
|
create_info->table_charset->name : "DEFAULT");
|
||||||
|
|
||||||
if (my_write(file,(byte*) path,strlen(path),MYF(MY_NABP+MY_WME)))
|
if (my_write(file,(byte*) path,strlen(path),MYF(MY_NABP+MY_WME)))
|
||||||
{
|
{
|
||||||
@ -423,15 +425,44 @@ bool mysql_change_db(THD *thd,const char *name)
|
|||||||
|
|
||||||
strcat(path,"/");
|
strcat(path,"/");
|
||||||
unpack_dirname(path,path);
|
unpack_dirname(path,path);
|
||||||
strcat(path,"db.opt");
|
strcat(path,MY_DB_OPT_FILE);
|
||||||
if ((file=my_open(path,O_RDWR|O_BINARY,MYF(MY_WME))) >= 0)
|
if ((file=my_open(path,O_RDWR|O_BINARY,MYF(MY_WME))) >= 0)
|
||||||
{
|
{
|
||||||
int nbytes=my_read(file,(byte*) path,sizeof(path),MYF(0));
|
int nbytes=my_read(file,(byte*) path,sizeof(path),MYF(0));
|
||||||
if ( nbytes >= 0 )
|
if ( nbytes >= 0 )
|
||||||
{
|
{
|
||||||
|
char *ln=path;
|
||||||
|
char *pe=path+nbytes;
|
||||||
|
|
||||||
path[nbytes]='\0';
|
path[nbytes]='\0';
|
||||||
// BAR TODO: parse create options
|
for ( ln=path; ln<pe; )
|
||||||
// and extract database default charset
|
{
|
||||||
|
char *le,*val;
|
||||||
|
for ( le=ln, val=0 ; le<pe ; le++ )
|
||||||
|
{
|
||||||
|
switch(le[0])
|
||||||
|
{
|
||||||
|
case '=':
|
||||||
|
le[0]='\0';
|
||||||
|
val=le+1;
|
||||||
|
le++;
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
le[0]='\0';
|
||||||
|
le++;
|
||||||
|
for( ; (le[0]=='\r' || le[0]=='\n') ; le++);
|
||||||
|
if (!strcmp(ln,"default-character-set") && val && val[0])
|
||||||
|
{
|
||||||
|
thd->db_charset=get_charset_by_name(val, MYF(0));
|
||||||
|
}
|
||||||
|
goto cnt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cnt:
|
||||||
|
ln=le;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
my_close(file,MYF(0));
|
my_close(file,MYF(0));
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
|||||||
auto_increment++;
|
auto_increment++;
|
||||||
if(!sql_field->charset)
|
if(!sql_field->charset)
|
||||||
sql_field->charset = create_info->table_charset ?
|
sql_field->charset = create_info->table_charset ?
|
||||||
create_info->table_charset : default_charset_info;
|
create_info->table_charset :
|
||||||
|
thd->db_charset? thd->db_charset :
|
||||||
|
default_charset_info;
|
||||||
pos+=sql_field->pack_length;
|
pos+=sql_field->pack_length;
|
||||||
}
|
}
|
||||||
if (auto_increment > 1)
|
if (auto_increment > 1)
|
||||||
|
Reference in New Issue
Block a user