diff options
-rw-r--r-- | sql/sp.cc | 18 | ||||
-rw-r--r-- | sql/sp.h | 3 | ||||
-rw-r--r-- | sql/sp_head.cc | 8 |
3 files changed, 16 insertions, 13 deletions
diff --git a/sql/sp.cc b/sql/sp.cc index 0d0152658b7..20fac74c150 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -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 diff --git a/sql/sp_head.cc b/sql/sp_head.cc index c22e57830f8..5263c59f4ad 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -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); |