summaryrefslogtreecommitdiff
path: root/sql/sp.cc
diff options
context:
space:
mode:
authorDmitry Shulga <Dmitry.Shulga@oracle.com>2011-06-24 00:02:58 +0700
committerDmitry Shulga <Dmitry.Shulga@oracle.com>2011-06-24 00:02:58 +0700
commite42a24e58c45c02d5c7561efde094769fdd57164 (patch)
treef8c73e20154892449146f9b034ae2b7c5210d353 /sql/sp.cc
parent7545f86670f6599dacaf934eb2932338529169b9 (diff)
parentbc7af1757939f1ec3c389da73176c7c68a8bafd5 (diff)
downloadmariadb-git-e42a24e58c45c02d5c7561efde094769fdd57164.tar.gz
Manual merge of patch for bug#11756013 from mysql-5.1 tree.
Diffstat (limited to 'sql/sp.cc')
-rw-r--r--sql/sp.cc49
1 files changed, 48 insertions, 1 deletions
diff --git a/sql/sp.cc b/sql/sp.cc
index ae11c2ad14c..7d778b56687 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -756,6 +756,43 @@ static sp_head *sp_compile(THD *thd, String *defstr, ulong sql_mode,
}
+class Bad_db_error_handler : public Internal_error_handler
+{
+public:
+ Bad_db_error_handler()
+ :m_error_caught(false)
+ {}
+
+ virtual bool handle_condition(THD *thd,
+ uint sql_errno,
+ const char* sqlstate,
+ MYSQL_ERROR::enum_warning_level level,
+ const char* message,
+ MYSQL_ERROR ** cond_hdl);
+
+ bool error_caught() const { return m_error_caught; }
+
+private:
+ bool m_error_caught;
+};
+
+bool
+Bad_db_error_handler::handle_condition(THD *thd,
+ uint sql_errno,
+ const char* sqlstate,
+ MYSQL_ERROR::enum_warning_level level,
+ const char* message,
+ MYSQL_ERROR ** cond_hdl)
+{
+ if (sql_errno == ER_BAD_DB_ERROR)
+ {
+ m_error_caught= true;
+ return true;
+ }
+ return false;
+}
+
+
static int
db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
ulong sql_mode, const char *params, const char *returns,
@@ -769,7 +806,7 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
LEX_STRING saved_cur_db_name=
{ saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) };
bool cur_db_changed;
-
+ Bad_db_error_handler db_not_exists_handler;
char definer_user_name_holder[USERNAME_LENGTH + 1];
LEX_STRING definer_user_name= { definer_user_name_holder,
USERNAME_LENGTH };
@@ -808,6 +845,7 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
goto end;
}
+ thd->push_internal_handler(&db_not_exists_handler);
/*
Change the current database (if needed).
@@ -818,6 +856,15 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
&cur_db_changed))
{
ret= SP_INTERNAL_ERROR;
+ thd->pop_internal_handler();
+ goto end;
+ }
+ thd->pop_internal_handler();
+ if (db_not_exists_handler.error_caught())
+ {
+ ret= SP_INTERNAL_ERROR;
+ my_error(ER_BAD_DB_ERROR, MYF(0), name->m_db.str);
+
goto end;
}