56
/* Database lock hash */
58
pthread_mutex_t LOCK_lock_db;
59
bool dbcache_init= false;
60
int creating_database= 0; // how many database locks are made
63
56
/* Structure for database lock */
64
57
typedef struct my_dblock_st
75
extern "C" unsigned char* lock_db_get_key(my_dblock_t *, size_t *, bool not_used);
77
unsigned char* lock_db_get_key(my_dblock_t *ptr, size_t *length,
80
*length= ptr->name_length;
81
return (unsigned char*) ptr->name;
86
Free lock_db hash element.
89
extern "C" void lock_db_free_element(void *ptr);
91
void lock_db_free_element(void *ptr)
98
Delete a database lock entry from hash.
101
void lock_db_delete(const char *name, uint32_t length)
104
safe_mutex_assert_owner(&LOCK_lock_db);
105
if ((opt= (my_dblock_t *)hash_search(&lock_db_cache,
106
(const unsigned char*) name, length)))
107
hash_delete(&lock_db_cache, (unsigned char*) opt);
111
Initialize database option hash and locked database hash.
117
Must be called before any other database function is called.
124
bool my_database_names_init(void)
130
error= hash_init(&lock_db_cache, &my_charset_bin,
131
32, 0, 0, (hash_get_key) lock_db_get_key,
132
lock_db_free_element,0);
139
65
Return default database collation.
779
Backup the current database name before switch.
781
@param[in] session thread handle
782
@param[in, out] saved_db_name IN: "str" points to a buffer where to store
783
the old database name, "length" contains the
785
OUT: if the current (default) database is
786
not NULL, its name is copied to the
787
buffer pointed at by "str"
788
and "length" is updated accordingly.
789
Otherwise "str" is set to NULL and
790
"length" is set to 0.
793
static void backup_current_db_name(Session *session,
794
LEX_STRING *saved_db_name)
798
/* No current (default) database selected. */
800
saved_db_name->str= NULL;
801
saved_db_name->length= 0;
805
strncpy(saved_db_name->str, session->db, saved_db_name->length - 1);
806
saved_db_name->length= session->db_length;
812
703
Return true if db1_name is equal to db2_name, false otherwise.
899
790
LEX_STRING new_db_file_name;
900
791
const CHARSET_INFO *db_default_cl;
902
if (new_db_name == NULL ||
903
new_db_name->length == 0)
908
This can happen only if we're switching the current database back
909
after loading stored program. The thing is that loading of stored
910
program can happen when there is no current database.
912
TODO: actually, new_db_name and new_db_name->str seem to be always
913
non-NULL. In case of stored program, new_db_name->str == "" and
914
new_db_name->length == 0.
917
mysql_change_db_impl(session, NULL);
923
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
794
assert(new_db_name->length);
929
796
if (my_strcasecmp(system_charset_info, new_db_name->str,
930
797
INFORMATION_SCHEMA_NAME.c_str()) == 0)
1023
Change the current database and its attributes if needed.
1025
@param session thread handle
1026
@param new_db_name database name
1027
@param[in, out] saved_db_name IN: "str" points to a buffer where to store
1028
the old database name, "length" contains the
1030
OUT: if the current (default) database is
1031
not NULL, its name is copied to the
1032
buffer pointed at by "str"
1033
and "length" is updated accordingly.
1034
Otherwise "str" is set to NULL and
1035
"length" is set to 0.
1036
@param force_switch @see mysql_change_db()
1037
@param[out] cur_db_changed out-flag to indicate whether the current
1038
database has been changed (valid only if
1039
the function suceeded)
1042
bool mysql_opt_change_db(Session *session,
1043
const LEX_STRING *new_db_name,
1044
LEX_STRING *saved_db_name,
1046
bool *cur_db_changed)
1048
*cur_db_changed= !cmp_db_names(session->db, new_db_name->str);
1050
if (!*cur_db_changed)
1053
backup_current_db_name(session, saved_db_name);
1055
return mysql_change_db(session, new_db_name, force_switch);
1060
889
Check if there is directory for the database name.