MySQL 8.4.3
Source Code Documentation
|
#include "lex_string.h"
Go to the source code of this file.
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
Functions | |
bool | mysql_create_db (THD *thd, const char *db, HA_CREATE_INFO *create) |
Create a database. More... | |
bool | mysql_alter_db (THD *thd, const char *db, HA_CREATE_INFO *create) |
bool | mysql_rm_db (THD *thd, const LEX_CSTRING &db, bool if_exists) |
Drop all tables, routines and events in a database and the database itself. More... | |
bool | mysql_change_db (THD *thd, const LEX_CSTRING &new_db_name, bool force_switch) |
Change the current database and its attributes unconditionally. More... | |
bool | mysql_opt_change_db (THD *thd, const LEX_CSTRING &new_db_name, LEX_STRING *saved_db_name, bool force_switch, bool *cur_db_changed) |
Change the current database and its attributes if needed. More... | |
bool | get_default_db_collation (const dd::Schema &schema, const CHARSET_INFO **collation) |
bool | get_default_db_collation (THD *thd, const char *db_name, const CHARSET_INFO **collation) |
Return default database collation. More... | |
bool | check_schema_readonly (THD *thd, const char *schema_name, TABLE_SHARE *share=nullptr) |
Check the read_only option for the given schema, and report error if the schema is not writable. More... | |
bool check_schema_readonly | ( | THD * | thd, |
const char * | schema_name, | ||
TABLE_SHARE * | share | ||
) |
Check the read_only option for the given schema, and report error if the schema is not writable.
thd | Thread context. |
schema_name | Name of schema to check. |
share | For tables, we cache the read only option in the table share, and can therefore get the read only option from the share. |
Caching the read only state in the table share is done for performance reasons. If a share is submitted, we get the read only state from the share. Otherwise, we get the schema object from the DD cache in order to see the read only state.
bool get_default_db_collation | ( | const dd::Schema & | schema, |
const CHARSET_INFO ** | collation | ||
) |
bool get_default_db_collation | ( | THD * | thd, |
const char * | db_name, | ||
const CHARSET_INFO ** | collation | ||
) |
Return default database collation.
thd | Thread context. | |
db_name | Database name. | |
[out] | collation | Charset object pointer if object exists else NULL. |
bool mysql_alter_db | ( | THD * | thd, |
const char * | db, | ||
HA_CREATE_INFO * | create | ||
) |
bool mysql_change_db | ( | THD * | thd, |
const LEX_CSTRING & | new_db_name, | ||
bool | force_switch | ||
) |
Change the current database and its attributes unconditionally.
thd | thread handle |
new_db_name | database name |
force_switch | if force_switch is false, then the operation will fail if - new_db_name is NULL or empty; - OR new database name is invalid (check_db_name() failed); - OR user has no privilege on the new database; - OR new database does not exist; if force_switch is true, then - if new_db_name is NULL or empty, the current database will be NULL, @@collation_database will be set to @@collation_server, the operation will succeed. - if new database name is invalid (check_db_name() failed), the current database will be NULL, @@collation_database will be set to @@collation_server, but the operation will fail; - user privileges will not be checked (THD::db_access however is updated); TODO: is this really the intention? (see sp-security.test). - if new database does not exist,the current database will be NULL, @@collation_database will be set to @@collation_server, a warning will be thrown, the operation will succeed. |
The function checks that the database name corresponds to a valid and existent database, checks access rights and changes the current database with database attributes (@collation_database session variable, THD::db_access).
This function is not the only way to switch the database that is currently employed. When the replication slave thread switches the database before executing a query, it calls thd->set_db directly. However, if the query, in turn, uses a stored routine, the stored routine will use this function, even if it's run on the slave.
This function allocates the name of the database on the system heap: this is necessary to be able to uniformly change the database from any module of the server. Up to 5.0 different modules were using different memory to store the name of the database, and this led to memory corruption: a stack pointer set by Stored Procedures was used by replication after the stack address was long gone.
false | Success |
true | Error |
bool mysql_create_db | ( | THD * | thd, |
const char * | db, | ||
HA_CREATE_INFO * | create_info | ||
) |
Create a database.
thd | Thread handler |
db | Name of database to create Function assumes that this is already validated. |
create_info | Database create options (like character set) |
SIDE-EFFECTS
false | ok |
true | Error |
bool mysql_opt_change_db | ( | THD * | thd, |
const LEX_CSTRING & | new_db_name, | ||
LEX_STRING * | saved_db_name, | ||
bool | force_switch, | ||
bool * | cur_db_changed | ||
) |
Change the current database and its attributes if needed.
thd | thread handle | |
new_db_name | database name | |
[in,out] | saved_db_name | IN: "str" points to a buffer where to store the old database name, "length" contains the buffer size OUT: if the current (default) database is not NULL, its name is copied to the buffer pointed at by "str" and "length" is updated accordingly. Otherwise "str" is set to NULL and "length" is set to 0. |
force_switch | if the change of the current database shall be forced |
[out] | cur_db_changed | out-flag to indicate whether the current database has been changed (valid only if the function succeeded) |
bool mysql_rm_db | ( | THD * | thd, |
const LEX_CSTRING & | db, | ||
bool | if_exists | ||
) |
Drop all tables, routines and events in a database and the database itself.
thd | Thread handle |
db | Database name in the case given by user It's already validated and set to lower case (if needed) when we come here |
if_exists | Don't give error if database doesn't exists |
false | OK (Database dropped) |
true | Error |