Commit 54e3909b authored by unknown's avatar unknown

Fixed proper restoring of current db on errors.

This fixes part of BUG#3229: Stored procedure comment causes packets out of order.


sql/sp.cc:
  Fixed proper restoring of current db on errors.
sql/sp.h:
  Fixed proper restoring of current db on errors.
sql/sp_head.cc:
  Fixed proper restoring of current db on errors.
parent 8a2b50c4
......@@ -219,7 +219,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
ulong deflen;
LEX *oldlex= thd->lex;
char olddb[128];
char *olddbptr;
bool dbchanged;
enum enum_sql_command oldcmd= thd->lex->sql_command;
ulong old_sql_mode= thd->variables.sql_mode;
ha_rows select_limit= thd->variables.select_limit;
......@@ -239,8 +239,9 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
goto done;
}
olddbptr= thd->db;
if ((ret= sp_use_new_db(thd, name->m_db.str, olddb, sizeof(olddb), 1)))
dbchanged= FALSE;
if ((ret= sp_use_new_db(thd, name->m_db.str, olddb, sizeof(olddb),
1, &dbchanged)))
goto done;
{
......@@ -262,8 +263,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
LEX *newlex= thd->lex;
sp_head *sp= newlex->sphead;
if (olddbptr != thd->db &&
(ret= sp_change_db(thd, olddb, 1)))
if (dbchanged && (ret= sp_change_db(thd, olddb, 1)))
goto done;
if (sp)
{
......@@ -276,8 +276,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
}
else
{
if (olddbptr != thd->db &&
(ret= sp_change_db(thd, olddb, 1)))
if (dbchanged && (ret= sp_change_db(thd, olddb, 1)))
goto done;
*sphp= thd->lex->sphead;
(*sphp)->set_info((char *)definer, (uint)strlen(definer),
......@@ -990,7 +989,7 @@ create_string(THD *thd, ulong *lenp,
int
sp_use_new_db(THD *thd, char *newdb, char *olddb, uint olddblen,
bool no_access_check)
bool no_access_check, bool *dbchangedp)
{
bool changeit;
DBUG_ENTER("sp_use_new_db");
......@@ -1016,12 +1015,15 @@ sp_use_new_db(THD *thd, char *newdb, char *olddb, uint olddblen,
}
if (!changeit)
{
*dbchangedp= FALSE;
DBUG_RETURN(0);
}
else
{
int ret= sp_change_db(thd, newdb, no_access_check);
if (! ret)
*dbchangedp= TRUE;
DBUG_RETURN(ret);
}
}
......
......@@ -93,9 +93,10 @@ sp_cache_functions(THD *thd, LEX *lex);
// Do a "use newdb". The current db is stored at olddb.
// If newdb is the same as the current one, nothing is changed.
// dbchangedp is set to true if the db was actually changed.
int
sp_use_new_db(THD *thd, char *newdb, char *olddb, uint olddbmax,
bool no_access_check);
bool no_access_check, bool *dbchangedp);
// Like mysql_change_db() but handles empty db name and the send_ok() problem.
int
......
......@@ -376,7 +376,7 @@ sp_head::execute(THD *thd)
{
DBUG_ENTER("sp_head::execute");
char olddb[128];
char *olddbptr;
bool dbchanged;
sp_rcontext *ctx= thd->spcont;
int ret= 0;
uint ip= 0;
......@@ -388,8 +388,8 @@ sp_head::execute(THD *thd)
}
#endif
olddbptr= thd->db;
if ((ret= sp_use_new_db(thd, m_db.str, olddb, sizeof(olddb), 0)))
dbchanged= FALSE;
if ((ret= sp_use_new_db(thd, m_db.str, olddb, sizeof(olddb), 0, &dbchanged)))
goto done;
if (ctx)
......@@ -445,7 +445,7 @@ sp_head::execute(THD *thd)
ret= -1;
/* If the DB has changed, the pointer has changed too, but the
original thd->db will then have been freed */
if (olddbptr != thd->db)
if (dbchanged)
{
if (! thd->killed)
ret= sp_change_db(thd, olddb, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment