23
25
#include <drizzled/server_includes.h>
24
26
#include <mysys/mysys_err.h>
25
27
#include <mysys/my_dir.h>
27
#include <drizzled/drizzled_error_messages.h>
28
#include <libdrizzle/gettext.h>
28
#include <drizzled/error.h>
29
#include <drizzled/gettext.h>
30
#include <mysys/hash.h>
31
#include <drizzled/session.h>
32
#include <drizzled/db.h>
33
#include <drizzled/sql_base.h>
34
#include <drizzled/lock.h>
35
#include <drizzled/errmsg_print.h>
36
#include <drizzled/replicator.h>
38
#define MY_DB_OPT_FILE "db.opt"
31
39
#define MAX_DROP_TABLE_Q_LEN 1024
33
41
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NULL};
34
42
static TYPELIB deletable_extentions=
35
43
{array_elements(del_exts)-1,"del_exts", del_exts, NULL};
37
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
38
const char *db, const char *path, uint32_t level,
45
static long mysql_rm_known_files(Session *session, MY_DIR *dirp,
46
const char *db, const char *path,
39
48
TableList **dropped_tables);
41
50
static bool rm_dir_w_symlink(const char *org_path, bool send_error);
42
static void mysql_change_db_impl(THD *thd,
51
static void mysql_change_db_impl(Session *session,
43
52
LEX_STRING *new_db_name,
44
53
const CHARSET_INFO * const new_db_charset);
97
107
hash_delete(&lock_db_cache, (unsigned char*) opt);
101
/* Database options hash */
102
static HASH dboptions;
103
static bool dboptions_init= 0;
104
static rw_lock_t LOCK_dboptions;
106
/* Structure for database options */
107
typedef struct my_dbopt_st
109
char *name; /* Database name */
110
uint32_t name_length; /* Database length name */
111
const CHARSET_INFO *charset; /* Database default character set */
116
Function we use in the creation of our hash to get key.
119
extern "C" unsigned char* dboptions_get_key(my_dbopt_t *opt, size_t *length,
122
unsigned char* dboptions_get_key(my_dbopt_t *opt, size_t *length,
123
bool not_used __attribute__((unused)))
125
*length= opt->name_length;
126
return (unsigned char*) opt->name;
131
111
Helper function to write a query to binlog used by mysql_rm_db()
134
static inline void write_to_binlog(THD *thd, char *query, uint32_t q_len,
135
char *db, uint32_t db_len)
114
static inline void write_to_binlog(Session *session, char *query, uint32_t query_length, char *, uint32_t)
137
Query_log_event qinfo(thd, query, q_len, 0, 0);
140
qinfo.db_len= db_len;
141
mysql_bin_log.write(&qinfo);
116
(void)replicator_statement(session, query, query_length);
146
Function to free dboptions hash element
149
extern "C" void free_dbopt(void *dbopt);
151
void free_dbopt(void *dbopt)
153
free((unsigned char*) dbopt);
158
120
Initialize database option hash and locked database hash.
194
Free database option hash and locked databases hash.
197
void my_database_names_free(void)
202
hash_free(&dboptions);
203
(void) rwlock_destroy(&LOCK_dboptions);
204
hash_free(&lock_db_cache);
210
Cleanup cached options
213
void my_dbopt_cleanup(void)
215
rw_wrlock(&LOCK_dboptions);
216
hash_free(&dboptions);
217
hash_init(&dboptions, lower_case_table_names ?
218
&my_charset_bin : system_charset_info,
219
32, 0, 0, (hash_get_key) dboptions_get_key,
221
rw_unlock(&LOCK_dboptions);
226
Find database options in the hash.
229
Search a database options in the hash, usings its path.
230
Fills "create" on success.
237
static bool get_dbopt(const char *dbname, HA_CREATE_INFO *create)
243
length= (uint) strlen(dbname);
245
rw_rdlock(&LOCK_dboptions);
246
if ((opt= (my_dbopt_t*) hash_search(&dboptions, (unsigned char*) dbname, length)))
248
create->default_table_charset= opt->charset;
251
rw_unlock(&LOCK_dboptions);
257
Writes database options into the hash.
260
Inserts database options into the hash, or updates
261
options if they are already in the hash.
268
static bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
274
length= (uint) strlen(dbname);
276
rw_wrlock(&LOCK_dboptions);
277
if (!(opt= (my_dbopt_t*) hash_search(&dboptions, (unsigned char*) dbname, length)))
279
/* Options are not in the hash, insert them */
281
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
282
&opt, (uint) sizeof(*opt), &tmp_name, (uint) length+1,
290
my_stpcpy(opt->name, dbname);
291
opt->name_length= length;
293
if ((error= my_hash_insert(&dboptions, (unsigned char*) opt)))
300
/* Update / write options in hash */
301
opt->charset= create->default_table_charset;
304
rw_unlock(&LOCK_dboptions);
310
Deletes database options from the hash.
313
void del_dbopt(const char *path)
316
rw_wrlock(&LOCK_dboptions);
317
if ((opt= (my_dbopt_t *)hash_search(&dboptions, (const unsigned char*) path,
319
hash_delete(&dboptions, (unsigned char*) opt);
320
rw_unlock(&LOCK_dboptions);
325
Create database options file:
328
Currently database default charset is only stored there.
332
1 Could not create file or write to it. Error sent through my_error()
335
static bool write_db_opt(THD *thd, const char *path, const char *name, HA_CREATE_INFO *create)
149
Return default database collation.
151
@param session Thread context.
152
@param db_name Database name.
154
@return CHARSET_INFO object. The operation always return valid character
155
set, even if the database does not exist.
158
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name)
160
HA_CREATE_INFO db_info;
162
if (session->db != NULL && strcmp(db_name, session->db) == 0)
163
return session->db_charset;
166
db_info.default_table_charset contains valid character set
170
load_db_opt_by_name(session, db_name, &db_info);
172
return db_info.default_table_charset;
175
/* path is path to database, not schema file */
176
static int write_schema_file(Session *session,
177
const char *path, const char *name,
178
HA_CREATE_INFO *create)
338
180
drizzle::Schema db;
181
char schema_file_tmp[FN_REFLEN];
182
string schema_file(path);
188
snprintf(schema_file_tmp, FN_REFLEN, "%s%c%s.tmpXXXXXX", path, FN_LIBCHAR, MY_DB_OPT_FILE);
190
schema_file.append(1, FN_LIBCHAR);
191
schema_file.append(MY_DB_OPT_FILE);
193
int fd= mkstemp(schema_file_tmp);
342
198
if (!create->default_table_charset)
343
create->default_table_charset= thd->variables.collation_server;
345
if (put_dbopt(path, create))
199
create->default_table_charset= session->variables.collation_server;
348
201
db.set_name(name);
349
db.set_characterset(create->default_table_charset->csname);
350
202
db.set_collation(create->default_table_charset->name);
352
fstream output(path, ios::out | ios::trunc | ios::binary);
353
if (!db.SerializeToOstream(&output))
204
if (!db.SerializeToFileDescriptor(fd))
207
unlink(schema_file_tmp);
211
if (rename(schema_file_tmp, schema_file.c_str()) == -1)
361
Load database options file
364
path Path for option file
365
create Where to store the read options
371
1 No database file or could not open it
375
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
221
int load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create)
378
223
drizzle::Schema db;
381
226
memset(create, 0, sizeof(*create));
382
create->default_table_charset= thd->variables.collation_server;
384
/* Check if options for this database are already in the hash */
385
if (!get_dbopt(path, create))
388
fstream input(path, ios::in | ios::binary);
391
else if (!db.ParseFromIstream(&input))
394
buffer= db.characterset();
395
if (!(create->default_table_charset= get_charset_by_csname(buffer.c_str(), MY_CS_PRIMARY, MYF(0))))
227
create->default_table_charset= session->variables.collation_server;
229
int fd= open(path, O_RDONLY);
234
if (!db.ParseFromFileDescriptor(fd))
397
sql_print_error(_("Error while loading database options: '%s':"),path);
398
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
399
create->default_table_charset= default_charset_info;
402
241
buffer= db.collation();
403
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str(), MYF(0))))
242
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str())))
405
sql_print_error(_("Error while loading database options: '%s':"),path);
406
sql_print_error(ER(ER_UNKNOWN_COLLATION), buffer.c_str());
244
errmsg_printf(ERRMSG_LVL_ERROR,
245
_("Error while loading database options: '%s':"),path);
246
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
407
247
create->default_table_charset= default_charset_info;
411
Put the loaded value into the hash.
412
Note that another thread could've added the same
413
entry to the hash after we called get_dbopt(),
414
but it's not an error, as put_dbopt() takes this
415
possibility into account.
417
error= put_dbopt(path, create);
425
Retrieve database options by name. Load database options file or fetch from
429
load_db_opt_by_name()
430
db_name Database name
431
db_create_info Where to store the database options
434
load_db_opt_by_name() is a shortcut for load_db_opt().
437
Although load_db_opt_by_name() (and load_db_opt()) returns status of
438
the operation, it is useless usually and should be ignored. The problem
439
is that there are 1) system databases ("mysql") and 2) virtual
440
databases ("information_schema"), which do not contain options file.
441
So, load_db_opt[_by_name]() returns false for these databases, but this
444
load_db_opt[_by_name]() clears db_create_info structure in any case, so
445
even on failure it contains valid data. So, common use case is just
446
call load_db_opt[_by_name]() without checking return value and use
447
db_create_info right after that.
449
RETURN VALUES (read NOTE!)
451
true Failed to retrieve options
454
bool load_db_opt_by_name(THD *thd, const char *db_name,
455
HA_CREATE_INFO *db_create_info)
254
int load_db_opt_by_name(Session *session, const char *db_name,
255
HA_CREATE_INFO *db_create_info)
457
257
char db_opt_path[FN_REFLEN];
543
311
Do not create database if another thread is holding read lock.
544
Wait for global read lock before acquiring LOCK_mysql_create_db.
312
Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
545
313
After wait_if_global_read_lock() we have protection against another
546
global read lock. If we would acquire LOCK_mysql_create_db first,
314
global read lock. If we would acquire LOCK_drizzleclient_create_db first,
547
315
another thread could step in and get the global read lock before we
548
316
reach wait_if_global_read_lock(). If this thread tries the same as we
549
(admin a db), it would then go and wait on LOCK_mysql_create_db...
317
(admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
550
318
Furthermore wait_if_global_read_lock() checks if the current thread
551
319
has the global read lock and refuses the operation with
552
320
ER_CANT_UPDATE_WITH_READLOCK if applicable.
554
if (wait_if_global_read_lock(thd, 0, 1))
322
if (wait_if_global_read_lock(session, 0, 1))
560
pthread_mutex_lock(&LOCK_mysql_create_db);
328
pthread_mutex_lock(&LOCK_drizzleclient_create_db);
562
330
/* Check directory */
563
331
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
564
332
path[path_len-1]= 0; // Remove last '/' from path
566
if (!stat(path,&stat_info))
334
if (mkdir(path,0777) == -1)
568
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
570
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
338
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
340
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
344
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
345
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db);
574
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
575
ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db);
352
my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno);
585
my_error(EE_STAT, MYF(0), path, errno);
588
if (my_mkdir(path,0777,MYF(0)) < 0)
590
my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno);
596
path[path_len-1]= FN_LIBCHAR;
597
strmake(path+path_len, MY_DB_OPT_FILE, sizeof(path)-path_len-1);
598
if (write_db_opt(thd, path, db, create_info))
357
error= write_schema_file(session, path, db, create_info);
358
if (error && error != EEXIST)
601
Could not create options file.
602
Restore things to beginning.
605
360
if (rmdir(path) >= 0)
611
We come here when we managed to create the database, but not the option
612
file. In this case it's best to just continue as if nothing has
613
happened. (This is a very unlikely senario)
620
370
uint32_t query_length;
622
if (!thd->query) // Only in replication
372
if (!session->query) // Only in replication
625
query_length= (uint) (strxmov(tmp_query,"create database `",
626
db, "`", NULL) - tmp_query);
375
query_length= sprintf(tmp_query, "create database `%s`", db);
631
query_length= thd->query_length;
634
if (mysql_bin_log.is_open())
636
Query_log_event qinfo(thd, query, query_length, 0,
637
/* suppress_use */ true);
640
Write should use the database being created as the "current
641
database" and not the threads current database, which is the
642
default. If we do not change the "current database" to the
643
database being created, the CREATE statement will not be
644
replicated when using --binlog-do-db to select databases to be
647
An example (--binlog-do-db=sisyfos):
649
CREATE DATABASE bob; # Not replicated
650
USE bob; # 'bob' is the current database
651
CREATE DATABASE sisyfos; # Not replicated since 'bob' is
653
USE sisyfos; # Will give error on slave since
654
# database does not exist.
657
qinfo.db_len = strlen(db);
659
/* These DDL methods and logging protected with LOCK_mysql_create_db */
660
mysql_bin_log.write(&qinfo);
379
query= session->query;
380
query_length= session->query_length;
383
(void)replicator_statement(session, query, query_length);
384
session->my_ok(result);
666
pthread_mutex_unlock(&LOCK_mysql_create_db);
667
start_waiting_global_read_lock(thd);
388
pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
389
start_waiting_global_read_lock(session);
673
395
/* db-name is already validated when we come here */
675
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
397
bool mysql_alter_db(Session *session, const char *db, HA_CREATE_INFO *create_info)
677
char path[FN_REFLEN+16];
401
char path[FN_REFLEN+16];
682
405
Do not alter database if another thread is holding read lock.
683
Wait for global read lock before acquiring LOCK_mysql_create_db.
406
Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
684
407
After wait_if_global_read_lock() we have protection against another
685
global read lock. If we would acquire LOCK_mysql_create_db first,
408
global read lock. If we would acquire LOCK_drizzleclient_create_db first,
686
409
another thread could step in and get the global read lock before we
687
410
reach wait_if_global_read_lock(). If this thread tries the same as we
688
(admin a db), it would then go and wait on LOCK_mysql_create_db...
411
(admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
689
412
Furthermore wait_if_global_read_lock() checks if the current thread
690
413
has the global read lock and refuses the operation with
691
414
ER_CANT_UPDATE_WITH_READLOCK if applicable.
693
if ((error=wait_if_global_read_lock(thd,0,1)))
696
pthread_mutex_lock(&LOCK_mysql_create_db);
699
Recreate db options file: /dbpath/.db.opt
700
We pass MY_DB_OPT_FILE as "extension" to avoid
701
"table name to file name" encoding.
703
build_table_filename(path, sizeof(path), db, "", MY_DB_OPT_FILE, 0);
704
if ((error=write_db_opt(thd, path, db, create_info)))
416
if ((error=wait_if_global_read_lock(session,0,1)))
419
pthread_mutex_lock(&LOCK_drizzleclient_create_db);
707
421
/* Change options if current database is being altered. */
709
if (thd->db && !strcmp(thd->db,db))
711
thd->db_charset= create_info->default_table_charset ?
422
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
423
path[path_len-1]= 0; // Remove last '/' from path
425
error= write_schema_file(session, path, db, create_info);
426
if (error && error != EEXIST)
428
/* TODO: find some witty way of getting back an error message */
429
pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
433
if (session->db && !strcmp(session->db,db))
435
session->db_charset= create_info->default_table_charset ?
712
436
create_info->default_table_charset :
713
thd->variables.collation_server;
714
thd->variables.collation_database= thd->db_charset;
717
if (mysql_bin_log.is_open())
719
Query_log_event qinfo(thd, thd->query, thd->query_length, 0,
720
/* suppress_use */ true);
723
Write should use the database being created as the "current
724
database" and not the threads current database, which is the
728
qinfo.db_len = strlen(db);
731
/* These DDL methods and logging protected with LOCK_mysql_create_db */
732
mysql_bin_log.write(&qinfo);
437
session->variables.collation_server;
438
session->variables.collation_database= session->db_charset;
441
(void)replicator_statement(session, session->query, session->query_length);
442
session->my_ok(result);
444
pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
445
start_waiting_global_read_lock(session);
737
pthread_mutex_unlock(&LOCK_mysql_create_db);
738
start_waiting_global_read_lock(thd);
770
477
if (db && (strcmp(db, "information_schema") == 0))
772
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
479
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
777
484
Do not drop database if another thread is holding read lock.
778
Wait for global read lock before acquiring LOCK_mysql_create_db.
485
Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
779
486
After wait_if_global_read_lock() we have protection against another
780
global read lock. If we would acquire LOCK_mysql_create_db first,
487
global read lock. If we would acquire LOCK_drizzleclient_create_db first,
781
488
another thread could step in and get the global read lock before we
782
489
reach wait_if_global_read_lock(). If this thread tries the same as we
783
(admin a db), it would then go and wait on LOCK_mysql_create_db...
490
(admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
784
491
Furthermore wait_if_global_read_lock() checks if the current thread
785
492
has the global read lock and refuses the operation with
786
493
ER_CANT_UPDATE_WITH_READLOCK if applicable.
788
if (wait_if_global_read_lock(thd, 0, 1))
495
if (wait_if_global_read_lock(session, 0, 1))
794
pthread_mutex_lock(&LOCK_mysql_create_db);
797
This statement will be replicated as a statement, even when using
798
row-based replication. The flag will be reset at the end of the
801
thd->clear_current_stmt_binlog_row_based();
501
pthread_mutex_lock(&LOCK_drizzleclient_create_db);
803
503
length= build_table_filename(path, sizeof(path), db, "", "", 0);
804
my_stpcpy(path+length, MY_DB_OPT_FILE); // Append db option file name
805
del_dbopt(path); // Remove dboption hash entry
504
strcpy(path+length, MY_DB_OPT_FILE); // Append db option file name
806
506
path[length]= '\0'; // Remove file name
808
508
/* See if the directory exists */
838
538
const char *query;
839
539
uint32_t query_length;
842
542
/* The client used the old obsolete mysql_drop_db() call */
844
query_length= (uint) (strxmov(path, "drop database `", db, "`",
544
query_length= sprintf(path, "drop database `%s`", db);
850
query_length= thd->query_length;
852
if (mysql_bin_log.is_open())
854
Query_log_event qinfo(thd, query, query_length, 0,
855
/* suppress_use */ true);
857
Write should use the database being created as the "current
858
database" and not the threads current database, which is the
862
qinfo.db_len = strlen(db);
865
/* These DDL methods and logging protected with LOCK_mysql_create_db */
866
mysql_bin_log.write(&qinfo);
869
thd->server_status|= SERVER_STATUS_DB_DROPPED;
870
my_ok(thd, (uint32_t) deleted);
871
thd->server_status&= ~SERVER_STATUS_DB_DROPPED;
548
query= session->query;
549
query_length= session->query_length;
551
(void)replicator_statement(session, session->query, session->query_length);
552
session->clear_error();
553
session->server_status|= SERVER_STATUS_DB_DROPPED;
554
session->my_ok((uint32_t) deleted);
555
session->server_status&= ~SERVER_STATUS_DB_DROPPED;
873
else if (mysql_bin_log.is_open())
875
559
char *query, *query_pos, *query_end, *query_data_start;
879
if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN)))
563
if (!(query= (char*) session->alloc(MAX_DROP_TABLE_Q_LEN)))
880
564
goto exit; /* not much else we can do */
881
query_pos= query_data_start= my_stpcpy(query,"drop table ");
565
query_pos= query_data_start= strcpy(query,"drop table ")+11;
882
566
query_end= query + MAX_DROP_TABLE_Q_LEN;
883
567
db_len= strlen(db);
955
639
extension= strchr(file->name, '\0');
956
640
if (find_type(extension, &deletable_extentions,1+2) <= 0)
958
if (find_type(extension, ha_known_exts(),1+2) <= 0)
645
strange checking for magic extensions that are then deleted if
646
not reg_ext (i.e. .frm).
648
and (previously) we'd err out on drop database if files not matching
649
engine ha_known_exts() or deletable_extensions were present.
651
presumably this was to avoid deleting other user data... except if that
652
data happened to be in files ending in .BAK, .opt or .TMD. *fun*
654
find_type(extension, ha_known_exts(),1+2);
962
657
/* just for safety we use files_charset_info */
963
658
if (db && !my_strcasecmp(files_charset_info,
964
659
extension, reg_ext))
661
uint32_t db_len= strlen(db);
966
663
/* Drop the table nicely */
967
664
*extension= 0; // Remove extension
968
665
TableList *table_list=(TableList*)
969
thd->calloc(sizeof(*table_list) +
971
MYSQL50_TABLE_NAME_PREFIX_LENGTH +
666
session->calloc(sizeof(*table_list) +
668
MYSQL50_TABLE_NAME_PREFIX_LENGTH +
972
669
strlen(file->name) + 1);
976
673
table_list->db= (char*) (table_list+1);
977
table_list->table_name= my_stpcpy(table_list->db, db) + 1;
674
table_list->table_name= strcpy(table_list->db, db) + db_len + 1;
978
675
filename_to_tablename(file->name, table_list->table_name,
979
676
MYSQL50_TABLE_NAME_PREFIX_LENGTH +
980
677
strlen(file->name) + 1);
981
678
table_list->alias= table_list->table_name; // If lower_case_table_names=2
982
table_list->internal_tmp_table= is_prefix(file->name, tmp_file_prefix);
679
table_list->internal_tmp_table= is_prefix(file->name, TMP_FILE_PREFIX);
983
680
/* Link into list */
984
681
(*tot_list_next)= table_list;
985
682
tot_list_next= &table_list->next_local;
1090
787
@param new_db_charset Character set of the new database.
1093
static void mysql_change_db_impl(THD *thd,
790
static void mysql_change_db_impl(Session *session,
1094
791
LEX_STRING *new_db_name,
1095
792
const CHARSET_INFO * const new_db_charset)
1097
/* 1. Change current database in THD. */
794
/* 1. Change current database in Session. */
1099
796
if (new_db_name == NULL)
1102
THD::set_db() does all the job -- it frees previous database name and
799
Session::set_db() does all the job -- it frees previous database name and
1103
800
sets the new one.
1106
thd->set_db(NULL, 0);
803
session->set_db(NULL, 0);
1108
else if (new_db_name == &INFORMATION_SCHEMA_NAME)
805
else if (my_strcasecmp(system_charset_info, new_db_name->str,
806
INFORMATION_SCHEMA_NAME.c_str()) == 0)
1111
Here we must use THD::set_db(), because we want to copy
809
Here we must use Session::set_db(), because we want to copy
1112
810
INFORMATION_SCHEMA_NAME constant.
1115
thd->set_db(INFORMATION_SCHEMA_NAME.str, INFORMATION_SCHEMA_NAME.length);
813
session->set_db(INFORMATION_SCHEMA_NAME.c_str(),
814
INFORMATION_SCHEMA_NAME.length());
1120
Here we already have a copy of database name to be used in THD. So,
1121
we just call THD::reset_db(). Since THD::reset_db() does not releases
819
Here we already have a copy of database name to be used in Session. So,
820
we just call Session::reset_db(). Since Session::reset_db() does not releases
1122
821
the previous database name, we should do it explicitly.
1128
thd->reset_db(new_db_name->str, new_db_name->length);
827
session->reset_db(new_db_name->str, new_db_name->length);
1131
830
/* 3. Update db-charset environment variables. */
1133
thd->db_charset= new_db_charset;
1134
thd->variables.collation_database= new_db_charset;
832
session->db_charset= new_db_charset;
833
session->variables.collation_database= new_db_charset;