mirror of
https://github.com/MariaDB/server.git
synced 2026-05-09 08:34:28 +02:00
WL#1366: Use the schema (db) associated with an SP.
Phase 2: Make SPs belong to a DB, and use qualified names.
As a side effect, using USE in an SP is no longer allowed.
(It just doesn't work otherwise.)
include/mysqld_error.h:
New error code (USE is no longer allowed in a stored procedure).
include/sql_state.h:
New error state (USE is no longer allowed in a stored procedure).
mysql-test/r/sp-error.result:
Updated result for test of USE in SP (not allowed now).
mysql-test/r/sp-security.result:
Updated test results for new db column and qualified procedured names.
mysql-test/r/sp.result:
Updated results for USE in SP (as it's no longer allowed), and
for new db column in status result.
mysql-test/t/sp-error.test:
Moved test of USE in SP from sp.test (as it's no longer allowed).
mysql-test/t/sp-security.test:
Ajusted tests for new db column and qualified procedured names.
mysql-test/t/sp.test:
Moved test of USE in SP to sp-error.test (as it's no longer allowed).
Adjusted tests for new db column in status result.
sql/mysql_priv.h:
mysql_change_db() now has optional arguments for use by SP with qualified names.
sql/share/czech/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/danish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/dutch/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/english/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/estonian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/french/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/german/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/greek/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/hungarian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/italian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/japanese/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/korean/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/norwegian-ny/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/norwegian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/polish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/portuguese/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/romanian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/russian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/serbian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/slovak/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/spanish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/swedish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/ukrainian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/sp.cc:
SPs are now "belong" to a DB and may have qualified names.
New functions for changing DB ("use") when parsing and invoking SPs.
sql/sp.h:
New functions for changing DB ("use") when parsing and invoking SPs.
sql/sp_cache.cc:
Use the qualified name in the SP cache.
sql/sp_head.cc:
New function for allocating a qualified SP name (used in sql_yacc.yy).
Change DB when executing an SP (if needed).
Moved thd_mem_root swap functions from sp_head.h.
sql/sp_head.h:
New function for allocating a qualified SP name (used in sql_yacc.yy).
Moved thd_mem_root swap functions to sp_head.cc.
sql/sql_db.cc:
mysql_change_db() now has optional arguments for use by SP with qualified names
(for use when reading an SP from database and executing it); also allow "unusing"
a database, i.e. setting thd->thd to "".
sql/sql_yacc.yy:
Initialize qualfied SP names correctly.
USE is no longer allowed in an SP.
This commit is contained in:
parent
5aa57221d8
commit
eb4aa092e5
39 changed files with 368 additions and 203 deletions
|
|
@ -595,7 +595,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
|
|||
1 error
|
||||
*/
|
||||
|
||||
bool mysql_change_db(THD *thd, const char *name)
|
||||
bool mysql_change_db(THD *thd, const char *name,
|
||||
bool empty_is_ok, bool no_access_check)
|
||||
{
|
||||
int length, db_length;
|
||||
char *dbname=my_strdup((char*) name,MYF(MY_WME));
|
||||
|
|
@ -604,62 +605,76 @@ bool mysql_change_db(THD *thd, const char *name)
|
|||
HA_CREATE_INFO create;
|
||||
DBUG_ENTER("mysql_change_db");
|
||||
|
||||
if (!dbname || !(db_length=strip_sp(dbname)))
|
||||
if ((!dbname || !(db_length=strip_sp(dbname))) && !empty_is_ok)
|
||||
{
|
||||
x_free(dbname); /* purecov: inspected */
|
||||
send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */
|
||||
DBUG_RETURN(1); /* purecov: inspected */
|
||||
}
|
||||
if ((db_length > NAME_LEN) || check_db_name(dbname))
|
||||
if (!empty_is_ok || (dbname && db_length))
|
||||
{
|
||||
net_printf(thd, ER_WRONG_DB_NAME, dbname);
|
||||
x_free(dbname);
|
||||
DBUG_RETURN(1);
|
||||
if ((db_length > NAME_LEN) || check_db_name(dbname))
|
||||
{
|
||||
net_printf(thd, ER_WRONG_DB_NAME, dbname);
|
||||
x_free(dbname);
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
}
|
||||
DBUG_PRINT("info",("Use database: %s", dbname));
|
||||
if (!empty_is_ok || (dbname && db_length))
|
||||
{
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
if (test_all_bits(thd->master_access,DB_ACLS))
|
||||
db_access=DB_ACLS;
|
||||
else
|
||||
db_access= (acl_get(thd->host,thd->ip, thd->priv_user,dbname,0) |
|
||||
thd->master_access);
|
||||
if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
|
||||
{
|
||||
net_printf(thd,ER_DBACCESS_DENIED_ERROR,
|
||||
thd->priv_user,
|
||||
thd->priv_host,
|
||||
dbname);
|
||||
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
|
||||
thd->priv_user,
|
||||
thd->priv_host,
|
||||
dbname);
|
||||
my_free(dbname,MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
if (! no_access_check)
|
||||
{
|
||||
if (test_all_bits(thd->master_access,DB_ACLS))
|
||||
db_access=DB_ACLS;
|
||||
else
|
||||
db_access= (acl_get(thd->host,thd->ip, thd->priv_user,dbname,0) |
|
||||
thd->master_access);
|
||||
if (!(db_access & DB_ACLS) &&
|
||||
(!grant_option || check_grant_db(thd,dbname)))
|
||||
{
|
||||
net_printf(thd,ER_DBACCESS_DENIED_ERROR,
|
||||
thd->priv_user,
|
||||
thd->priv_host,
|
||||
dbname);
|
||||
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
|
||||
thd->priv_user,
|
||||
thd->priv_host,
|
||||
dbname);
|
||||
my_free(dbname,MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
(void) sprintf(path,"%s/%s",mysql_data_home,dbname);
|
||||
length=unpack_dirname(path,path); // Convert if not unix
|
||||
if (length && path[length-1] == FN_LIBCHAR)
|
||||
path[length-1]=0; // remove ending '\'
|
||||
if (access(path,F_OK))
|
||||
{
|
||||
net_printf(thd,ER_BAD_DB_ERROR,dbname);
|
||||
my_free(dbname,MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
(void) sprintf(path,"%s/%s",mysql_data_home,dbname);
|
||||
length=unpack_dirname(path,path); // Convert if not unix
|
||||
if (length && path[length-1] == FN_LIBCHAR)
|
||||
path[length-1]=0; // remove ending '\'
|
||||
if (access(path,F_OK))
|
||||
{
|
||||
net_printf(thd,ER_BAD_DB_ERROR,dbname);
|
||||
my_free(dbname,MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
}
|
||||
send_ok(thd);
|
||||
x_free(thd->db);
|
||||
thd->db=dbname; // THD::~THD will free this
|
||||
thd->db_length=db_length;
|
||||
if (!empty_is_ok || (dbname && db_length))
|
||||
{
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
thd->db_access=db_access;
|
||||
if (! no_access_check)
|
||||
thd->db_access=db_access;
|
||||
#endif
|
||||
strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE);
|
||||
load_db_opt(thd, path, &create);
|
||||
thd->db_charset= create.default_table_charset ?
|
||||
create.default_table_charset :
|
||||
thd->variables.collation_server;
|
||||
thd->variables.collation_database= thd->db_charset;
|
||||
strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE);
|
||||
load_db_opt(thd, path, &create);
|
||||
thd->db_charset= create.default_table_charset ?
|
||||
create.default_table_charset :
|
||||
thd->variables.collation_server;
|
||||
thd->variables.collation_database= thd->db_charset;
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue