mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A fix and a test case for Bug#29050 Creation of a legal stored procedure
fails if a database is not selected prior. The problem manifested itself when a user tried to create a routine that had non-fully-qualified identifiers in its bodies and there was no current database selected. This is a regression introduced by the fix for Bug 19022: The patch for Bug 19022 changes the code to always produce a warning if we can't resolve the current database in the parser. In this case this was not necessary, since even though the produced parsed tree was incorrect, we never re-use sphead that was obtained at first parsing of CREATE PROCEDURE. The sphead that is anyhow used is always obtained through db_load_routine, and there we change the current database to sphead->m_db before calling yyparse. The idea of the fix is to resolve the current database directly using lex->sphead->m_db member when parsing a stored routine body, when such is present. This patch removes the need to reset the current database when loading a trigger or routine definition into SP cache. The redundant code will be removed in 5.1.
This commit is contained in:
@ -1974,6 +1974,43 @@ uint8 st_lex::get_effective_with_check(st_table_list *view)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This method should be called only during parsing.
|
||||
It is aware of compound statements (stored routine bodies)
|
||||
and will initialize the destination with the default
|
||||
database of the stored routine, rather than the default
|
||||
database of the connection it is parsed in.
|
||||
E.g. if one has no current database selected, or current database
|
||||
set to 'bar' and then issues:
|
||||
|
||||
CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
|
||||
|
||||
t1 is meant to refer to foo.t1, not to bar.t1.
|
||||
|
||||
This method is needed to support this rule.
|
||||
|
||||
@return TRUE in case of error (parsing should be aborted, FALSE in
|
||||
case of success
|
||||
*/
|
||||
|
||||
bool
|
||||
st_lex::copy_db_to(char **p_db, uint *p_db_length) const
|
||||
{
|
||||
if (sphead)
|
||||
{
|
||||
DBUG_ASSERT(sphead->m_db.str && sphead->m_db.length);
|
||||
/*
|
||||
It is safe to assign the string by-pointer, both sphead and
|
||||
its statements reside in the same memory root.
|
||||
*/
|
||||
*p_db= sphead->m_db.str;
|
||||
if (p_db_length)
|
||||
*p_db_length= sphead->m_db.length;
|
||||
return FALSE;
|
||||
}
|
||||
return thd->copy_db_to(p_db, p_db_length);
|
||||
}
|
||||
|
||||
/*
|
||||
initialize limit counters
|
||||
|
||||
|
Reference in New Issue
Block a user