summaryrefslogtreecommitdiff
path: root/sql/sql_db.cc
diff options
context:
space:
mode:
authorunknown <bar@gw.udmsearch.izhnet.ru>2002-06-27 14:41:02 +0500
committerunknown <bar@gw.udmsearch.izhnet.ru>2002-06-27 14:41:02 +0500
commit3c87e8da56e408ce4de1c9091a09250102514412 (patch)
tree6cee3854339fea9f32b3a4d2ad721ada7ec536e6 /sql/sql_db.cc
parent9fc8de40757a1ffafc5aa0e893a1aa08e9bd4cfb (diff)
downloadmariadb-git-3c87e8da56e408ce4de1c9091a09250102514412.tar.gz
ALTER DATABASE DEFAULT CHARACTER SET latin1;
Diffstat (limited to 'sql/sql_db.cc')
-rw-r--r--sql/sql_db.cc227
1 files changed, 158 insertions, 69 deletions
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 91f7474bb33..aa8030e5a3e 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -31,6 +31,96 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path,
uint level);
+/*
+ Create database options file:
+ Currently databse default charset is only stored there.
+*/
+
+static int write_db_opt(THD *thd, char *db, HA_CREATE_INFO *create, char *fn)
+{
+ register File file;
+ char buf[256]; // Should be enough
+ int error=0;
+
+ if ((file=my_create(fn,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
+ {
+ sprintf(buf,"default-character-set=%s\n",
+ (create && create->table_charset) ?
+ create->table_charset->name : "DEFAULT");
+
+ if (my_write(file,(byte*)buf,strlen(buf),MYF(MY_NABP+MY_WME)))
+ {
+ // QQ : should we send more suitable error message?
+ my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
+ error = -1;
+ goto exit;
+ }
+ my_close(file,MYF(0));
+ }
+ else
+ {
+ // QQ : should we send more suitable error message?
+ my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
+ error = -1;
+ goto exit;
+ }
+exit:
+ return error;
+}
+
+
+ /*
+ Load database options file:
+ */
+static int load_db_opt(THD *thd,char *fn)
+{
+ register File file;
+ char buf[256]="";
+
+ if ((file=my_open(fn,O_RDWR|O_BINARY,MYF(MY_WME))) >= 0)
+ {
+ int nbytes=my_read(file,(byte*)buf,sizeof(buf)-1,MYF(0));
+ if ( nbytes >= 0 )
+ {
+ char *ln=buf;
+ char *pe=buf+nbytes;
+
+ buf[nbytes]='\0';
+
+ for ( ln=buf; ln<pe; )
+ {
+ 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));
+ }
+ return 0;
+}
+
/* db-name is already validated when we come here */
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent)
@@ -39,10 +129,10 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent
MY_DIR *dirp;
long result=1;
int error = 0;
- DBUG_ENTER("mysql_create_db");
- register File file;
uint create_options = create_info ? create_info->options : 0;
-
+
+ DBUG_ENTER("mysql_create_db");
+
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
// do not create database if another thread is holding read lock
@@ -77,43 +167,81 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent
}
}
- /*
- Create database options file:
- Currently databse default charset is only stored there.
- */
-
strcat(path,"/");
unpack_dirname(path,path);
strcat(path,MY_DB_OPT_FILE);
- if ((file=my_create(path,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
+ if ((error=write_db_opt(thd,db,create_info,path)))
+ goto exit;
+
+ if (!silent)
{
- sprintf(path,"default-character-set=%s\n",
- (create_info && create_info->table_charset) ?
- create_info->table_charset->name : "DEFAULT");
-
- if (my_write(file,(byte*) path,strlen(path),MYF(MY_NABP+MY_WME)))
+ if (!thd->query)
{
- // QQ : should we send more suitable error message?
- my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
- error = -1;
- goto exit;
+ thd->query = path;
+ thd->query_length = (uint) (strxmov(path,"create database ", db, NullS)-
+ path);
}
- my_close(file,MYF(0));
+ {
+ mysql_update_log.write(thd,thd->query, thd->query_length);
+ if (mysql_bin_log.is_open())
+ {
+ Query_log_event qinfo(thd, thd->query);
+ mysql_bin_log.write(&qinfo);
+ }
+ }
+ if (thd->query == path)
+ {
+ thd->query = 0; // just in case
+ thd->query_length = 0;
+ }
+ send_ok(&thd->net, result);
}
- else
+
+exit:
+ start_waiting_global_read_lock(thd);
+exit2:
+ VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));
+ DBUG_RETURN(error);
+}
+
+
+/* db-name is already validated when we come here */
+
+int mysql_alter_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent)
+{
+ char path[FN_REFLEN+16];
+ MY_DIR *dirp;
+ long result=1;
+ int error = 0;
+ DBUG_ENTER("mysql_create_db");
+ register File file;
+ uint create_options = create_info ? create_info->options : 0;
+
+ printf("alter database\n");
+
+ VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
+
+ // do not alter database if another thread is holding read lock
+ if (wait_if_global_read_lock(thd,0))
{
- // QQ : should we send more suitable error message?
- my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
- error = -1;
- goto exit;
+ error= -1;
+ goto exit2;
}
+ /* Check directory */
+ (void)sprintf(path,"%s/%s", mysql_data_home, db);
+ strcat(path,"/");
+ unpack_dirname(path,path); // Convert if not unix
+ strcat(path,MY_DB_OPT_FILE);
+ if ((error=write_db_opt(thd,db,create_info,path)))
+ goto exit;
+
if (!silent)
{
if (!thd->query)
{
thd->query = path;
- thd->query_length = (uint) (strxmov(path,"create database ", db, NullS)-
+ thd->query_length = (uint) (strxmov(path,"alter database ", db, NullS)-
path);
}
{
@@ -139,6 +267,10 @@ exit2:
DBUG_RETURN(error);
}
+
+
+
+
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts};
@@ -368,7 +500,6 @@ bool mysql_change_db(THD *thd,const char *name)
char path[FN_REFLEN];
uint db_access;
DBUG_ENTER("mysql_change_db");
- register File file;
if (!dbname || !(db_length=strip_sp(dbname)))
{
@@ -419,53 +550,11 @@ bool mysql_change_db(THD *thd,const char *name)
thd->db_length=db_length;
thd->db_access=db_access;
- /*
- Load database options file:
- */
-
strcat(path,"/");
unpack_dirname(path,path);
strcat(path,MY_DB_OPT_FILE);
- if ((file=my_open(path,O_RDWR|O_BINARY,MYF(MY_WME))) >= 0)
- {
- int nbytes=my_read(file,(byte*) path,sizeof(path),MYF(0));
- if ( nbytes >= 0 )
- {
- char *ln=path;
- char *pe=path+nbytes;
+ load_db_opt(thd,path);
- path[nbytes]='\0';
- for ( ln=path; ln<pe; )
- {
- 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));
- }
DBUG_RETURN(0);
}