summaryrefslogtreecommitdiff
path: root/sql/sp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sp.cc')
-rw-r--r--sql/sp.cc42
1 files changed, 41 insertions, 1 deletions
diff --git a/sql/sp.cc b/sql/sp.cc
index ddddaee2e10..78d1dc7e22c 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -708,6 +708,37 @@ Silence_deprecated_warning::handle_error(uint sql_errno, const char *message,
}
+class Bad_db_error_handler : public Internal_error_handler
+{
+public:
+ Bad_db_error_handler()
+ :m_error_caught(false)
+ {}
+
+ virtual bool handle_error(uint sql_errno, const char *message,
+ MYSQL_ERROR::enum_warning_level level,
+ THD *thd);
+
+ bool error_caught() const { return m_error_caught; }
+
+private:
+ bool m_error_caught;
+};
+
+bool
+Bad_db_error_handler::handle_error(uint sql_errno, const char *message,
+ MYSQL_ERROR::enum_warning_level level,
+ THD *thd)
+{
+ 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,
@@ -725,7 +756,7 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
ha_rows old_select_limit= thd->variables.select_limit;
sp_rcontext *old_spcont= thd->spcont;
Silence_deprecated_warning warning_handler;
-
+ 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 };
@@ -766,6 +797,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).
@@ -776,9 +808,17 @@ 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;
+ }
thd->spcont= NULL;
{