17
17
/* create and drop of databases */
18
#include <drizzled/global.h>
21
#include <drizzled/serialize/serialize.h>
23
#include <drizzled/message/schema.pb.h>
22
24
using namespace std;
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/transaction_services.h>
38
extern drizzled::TransactionServices transaction_services;
40
#define MY_DB_OPT_FILE "db.opt"
31
41
#define MAX_DROP_TABLE_Q_LEN 1024
33
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NULL};
43
const char *del_exts[]= {".dfe", ".BAK", ".TMD",".opt", NULL};
34
44
static TYPELIB deletable_extentions=
35
45
{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,
47
static long mysql_rm_known_files(Session *session, MY_DIR *dirp,
48
const char *db, const char *path,
39
50
TableList **dropped_tables);
41
52
static bool rm_dir_w_symlink(const char *org_path, bool send_error);
42
static void mysql_change_db_impl(THD *thd,
53
static void mysql_change_db_impl(Session *session,
43
54
LEX_STRING *new_db_name,
44
55
const CHARSET_INFO * const new_db_charset);
97
109
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
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)
137
Query_log_event qinfo(thd, query, q_len, 0, 0);
140
qinfo.db_len= db_len;
141
mysql_bin_log.write(&qinfo);
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
113
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)
142
Return default database collation.
144
@param session Thread context.
145
@param db_name Database name.
147
@return CHARSET_INFO object. The operation always return valid character
148
set, even if the database does not exist.
151
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name)
153
HA_CREATE_INFO db_info;
155
if (session->db != NULL && strcmp(db_name, session->db) == 0)
156
return session->db_charset;
159
db_info.default_table_charset contains valid character set
163
load_db_opt_by_name(session, db_name, &db_info);
165
return db_info.default_table_charset;
168
/* path is path to database, not schema file */
169
static int write_schema_file(Session *session,
170
const char *path, const char *name,
171
HA_CREATE_INFO *create)
173
drizzled::message::Schema db;
174
char schema_file_tmp[FN_REFLEN];
175
string schema_file(path);
181
snprintf(schema_file_tmp, FN_REFLEN, "%s%c%s.tmpXXXXXX", path, FN_LIBCHAR, MY_DB_OPT_FILE);
183
schema_file.append(1, FN_LIBCHAR);
184
schema_file.append(MY_DB_OPT_FILE);
186
int fd= mkstemp(schema_file_tmp);
342
191
if (!create->default_table_charset)
343
create->default_table_charset= thd->variables.collation_server;
345
if (put_dbopt(path, create))
192
create->default_table_charset= session->variables.collation_server;
348
194
db.set_name(name);
349
db.set_characterset(create->default_table_charset->csname);
350
195
db.set_collation(create->default_table_charset->name);
352
fstream output(path, ios::out | ios::trunc | ios::binary);
353
if (!db.SerializeToOstream(&output))
197
if (!db.SerializeToFileDescriptor(fd))
200
unlink(schema_file_tmp);
204
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)
214
int load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create)
216
drizzled::message::Schema db;
381
219
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))))
220
create->default_table_charset= session->variables.collation_server;
222
int fd= open(path, O_RDONLY);
227
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
234
buffer= db.collation();
403
if (!(create->default_table_charset= get_charset_by_name(buffer.c_str(), MYF(0))))
235
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());
237
errmsg_printf(ERRMSG_LVL_ERROR,
238
_("Error while loading database options: '%s':"),path);
239
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
407
240
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)
247
int load_db_opt_by_name(Session *session, const char *db_name,
248
HA_CREATE_INFO *db_create_info)
457
250
char db_opt_path[FN_REFLEN];
543
304
Do not create database if another thread is holding read lock.
544
Wait for global read lock before acquiring LOCK_mysql_create_db.
305
Wait for global read lock before acquiring LOCK_create_db.
545
306
After wait_if_global_read_lock() we have protection against another
546
global read lock. If we would acquire LOCK_mysql_create_db first,
307
global read lock. If we would acquire LOCK_create_db first,
547
308
another thread could step in and get the global read lock before we
548
309
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...
310
(admin a db), it would then go and wait on LOCK_create_db...
550
311
Furthermore wait_if_global_read_lock() checks if the current thread
551
312
has the global read lock and refuses the operation with
552
313
ER_CANT_UPDATE_WITH_READLOCK if applicable.
554
if (wait_if_global_read_lock(thd, 0, 1))
315
if (wait_if_global_read_lock(session, 0, 1))
560
pthread_mutex_lock(&LOCK_mysql_create_db);
321
pthread_mutex_lock(&LOCK_create_db);
562
323
/* Check directory */
563
324
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
564
325
path[path_len-1]= 0; // Remove last '/' from path
566
if (!stat(path,&stat_info))
327
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);
331
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
333
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
337
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
338
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);
345
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))
350
error= write_schema_file(session, path, db, create_info);
351
if (error && error != EEXIST)
601
Could not create options file.
602
Restore things to beginning.
605
353
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
363
uint32_t query_length;
622
if (!thd->query) // Only in replication
365
if (!session->query) // Only in replication
625
query_length= (uint) (strxmov(tmp_query,"create database `",
626
db, "`", NULL) - tmp_query);
368
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);
372
query= session->query;
373
query_length= session->query_length;
376
transaction_services.rawStatement(session, query, query_length);
377
session->my_ok(result);
666
pthread_mutex_unlock(&LOCK_mysql_create_db);
667
start_waiting_global_read_lock(thd);
381
pthread_mutex_unlock(&LOCK_create_db);
382
start_waiting_global_read_lock(session);
673
388
/* db-name is already validated when we come here */
675
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
390
bool mysql_alter_db(Session *session, const char *db, HA_CREATE_INFO *create_info)
677
char path[FN_REFLEN+16];
394
char path[FN_REFLEN+16];
682
398
Do not alter database if another thread is holding read lock.
683
Wait for global read lock before acquiring LOCK_mysql_create_db.
399
Wait for global read lock before acquiring LOCK_create_db.
684
400
After wait_if_global_read_lock() we have protection against another
685
global read lock. If we would acquire LOCK_mysql_create_db first,
401
global read lock. If we would acquire LOCK_create_db first,
686
402
another thread could step in and get the global read lock before we
687
403
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...
404
(admin a db), it would then go and wait on LOCK_create_db...
689
405
Furthermore wait_if_global_read_lock() checks if the current thread
690
406
has the global read lock and refuses the operation with
691
407
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)))
409
if ((error=wait_if_global_read_lock(session,0,1)))
412
pthread_mutex_lock(&LOCK_create_db);
707
414
/* 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 ?
415
path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
416
path[path_len-1]= 0; // Remove last '/' from path
418
error= write_schema_file(session, path, db, create_info);
419
if (error && error != EEXIST)
421
/* TODO: find some witty way of getting back an error message */
422
pthread_mutex_unlock(&LOCK_create_db);
426
if (session->db && !strcmp(session->db,db))
428
session->db_charset= create_info->default_table_charset ?
712
429
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);
430
session->variables.collation_server;
431
session->variables.collation_database= session->db_charset;
434
transaction_services.rawStatement(session, session->getQueryString(), session->getQueryLength());
435
session->my_ok(result);
437
pthread_mutex_unlock(&LOCK_create_db);
438
start_waiting_global_read_lock(session);
737
pthread_mutex_unlock(&LOCK_mysql_create_db);
738
start_waiting_global_read_lock(thd);
770
470
if (db && (strcmp(db, "information_schema") == 0))
772
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
472
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
777
477
Do not drop database if another thread is holding read lock.
778
Wait for global read lock before acquiring LOCK_mysql_create_db.
478
Wait for global read lock before acquiring LOCK_create_db.
779
479
After wait_if_global_read_lock() we have protection against another
780
global read lock. If we would acquire LOCK_mysql_create_db first,
480
global read lock. If we would acquire LOCK_create_db first,
781
481
another thread could step in and get the global read lock before we
782
482
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...
483
(admin a db), it would then go and wait on LOCK_create_db...
784
484
Furthermore wait_if_global_read_lock() checks if the current thread
785
485
has the global read lock and refuses the operation with
786
486
ER_CANT_UPDATE_WITH_READLOCK if applicable.
788
if (wait_if_global_read_lock(thd, 0, 1))
488
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();
494
pthread_mutex_lock(&LOCK_create_db);
803
496
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
497
strcpy(path+length, MY_DB_OPT_FILE); // Append db option file name
806
499
path[length]= '\0'; // Remove file name
808
501
/* See if the directory exists */
838
531
const char *query;
839
532
uint32_t query_length;
842
535
/* The client used the old obsolete mysql_drop_db() call */
844
query_length= (uint) (strxmov(path, "drop database `", db, "`",
537
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;
541
query= session->query;
542
query_length= session->query_length;
544
transaction_services.rawStatement(session, session->getQueryString(), session->getQueryLength());
545
session->clear_error();
546
session->server_status|= SERVER_STATUS_DB_DROPPED;
547
session->my_ok((uint32_t) deleted);
548
session->server_status&= ~SERVER_STATUS_DB_DROPPED;
873
else if (mysql_bin_log.is_open())
875
552
char *query, *query_pos, *query_end, *query_data_start;
879
if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN)))
556
if (!(query= (char*) session->alloc(MAX_DROP_TABLE_Q_LEN)))
880
557
goto exit; /* not much else we can do */
881
query_pos= query_data_start= my_stpcpy(query,"drop table ");
558
query_pos= query_data_start= strcpy(query,"drop table ")+11;
882
559
query_end= query + MAX_DROP_TABLE_Q_LEN;
883
560
db_len= strlen(db);
955
632
extension= strchr(file->name, '\0');
956
633
if (find_type(extension, &deletable_extentions,1+2) <= 0)
958
if (find_type(extension, ha_known_exts(),1+2) <= 0)
638
strange checking for magic extensions that are then deleted if
639
not reg_ext (i.e. .frm).
641
and (previously) we'd err out on drop database if files not matching
642
engine ha_known_exts() or deletable_extensions were present.
644
presumably this was to avoid deleting other user data... except if that
645
data happened to be in files ending in .BAK, .opt or .TMD. *fun*
962
649
/* just for safety we use files_charset_info */
963
650
if (db && !my_strcasecmp(files_charset_info,
653
uint32_t db_len= strlen(db);
966
655
/* Drop the table nicely */
967
656
*extension= 0; // Remove extension
968
657
TableList *table_list=(TableList*)
969
thd->calloc(sizeof(*table_list) +
971
MYSQL50_TABLE_NAME_PREFIX_LENGTH +
658
session->calloc(sizeof(*table_list) +
972
660
strlen(file->name) + 1);
976
664
table_list->db= (char*) (table_list+1);
977
table_list->table_name= my_stpcpy(table_list->db, db) + 1;
665
table_list->table_name= strcpy(table_list->db, db) + db_len + 1;
978
666
filename_to_tablename(file->name, table_list->table_name,
979
MYSQL50_TABLE_NAME_PREFIX_LENGTH +
980
667
strlen(file->name) + 1);
981
668
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);
669
table_list->internal_tmp_table= is_prefix(file->name, TMP_FILE_PREFIX);
983
670
/* Link into list */
984
671
(*tot_list_next)= table_list;
985
672
tot_list_next= &table_list->next_local;
1090
777
@param new_db_charset Character set of the new database.
1093
static void mysql_change_db_impl(THD *thd,
780
static void mysql_change_db_impl(Session *session,
1094
781
LEX_STRING *new_db_name,
1095
782
const CHARSET_INFO * const new_db_charset)
1097
/* 1. Change current database in THD. */
784
/* 1. Change current database in Session. */
1099
786
if (new_db_name == NULL)
1102
THD::set_db() does all the job -- it frees previous database name and
789
Session::set_db() does all the job -- it frees previous database name and
1103
790
sets the new one.
1106
thd->set_db(NULL, 0);
793
session->set_db(NULL, 0);
1108
else if (new_db_name == &INFORMATION_SCHEMA_NAME)
795
else if (my_strcasecmp(system_charset_info, new_db_name->str,
796
INFORMATION_SCHEMA_NAME.c_str()) == 0)
1111
Here we must use THD::set_db(), because we want to copy
799
Here we must use Session::set_db(), because we want to copy
1112
800
INFORMATION_SCHEMA_NAME constant.
1115
thd->set_db(INFORMATION_SCHEMA_NAME.str, INFORMATION_SCHEMA_NAME.length);
803
session->set_db(INFORMATION_SCHEMA_NAME.c_str(),
804
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
809
Here we already have a copy of database name to be used in Session. So,
810
we just call Session::reset_db(). Since Session::reset_db() does not releases
1122
811
the previous database name, we should do it explicitly.
1128
thd->reset_db(new_db_name->str, new_db_name->length);
817
session->reset_db(new_db_name->str, new_db_name->length);
1131
820
/* 3. Update db-charset environment variables. */
1133
thd->db_charset= new_db_charset;
1134
thd->variables.collation_database= new_db_charset;
822
session->db_charset= new_db_charset;
823
session->variables.collation_database= new_db_charset;