summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2016-01-27 12:01:55 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2016-01-28 11:12:03 +0400
commitf3926cd18e2ba64f2643c6c4f6a981ed99868895 (patch)
tree907763729c758b45c954498aa3d8fa0c4287ae87 /sql/sql_prepare.cc
parent07e976294089cbc0c8cf46d984565e6136ffa9e8 (diff)
downloadmariadb-git-f3926cd18e2ba64f2643c6c4f6a981ed99868895.tar.gz
MDEV-5273 Prepared statement doesn't return metadata after prepare.
Fix for SHOW CREATE DATABASE.
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc57
1 files changed, 40 insertions, 17 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index ee0aa2d73fd..9b455433acf 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1812,6 +1812,14 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
}
+static bool send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *fields)
+{
+ return send_prep_stmt(stmt, fields->elements) ||
+ thd->protocol->send_result_set_metadata(fields, Protocol::SEND_EOF) ||
+ thd->protocol->flush();
+}
+
+
/**
Validate and prepare for execution SHOW CREATE TABLE statement.
@@ -1824,7 +1832,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
TRUE error, error message is set in THD
*/
-static int mysql_test_show_create_table(Prepared_statement *stmt,
+static bool mysql_test_show_create_table(Prepared_statement *stmt,
TABLE_LIST *tables)
{
DBUG_ENTER("mysql_test_show_create_table");
@@ -1833,22 +1841,31 @@ static int mysql_test_show_create_table(Prepared_statement *stmt,
char buff[2048];
String buffer(buff, sizeof(buff), system_charset_info);
- if (mysqld_show_create_get_fields(thd, tables, &fields, &buffer))
- goto err_exit;
-
- if (!stmt->is_sql_prepare())
- {
- if (send_prep_stmt(stmt, fields.elements) ||
- thd->protocol->send_result_set_metadata(&fields, Protocol::SEND_EOF) ||
- thd->protocol->flush())
- goto err_exit;
+ DBUG_RETURN(mysqld_show_create_get_fields(thd, tables, &fields, &buffer) ||
+ send_stmt_metadata(thd, stmt, &fields));
+}
- DBUG_RETURN(2);
- }
- DBUG_RETURN(0);
-err_exit:
- DBUG_RETURN(1);
+/**
+ Validate and prepare for execution SHOW CREATE DATABASE statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static bool mysql_test_show_create_db(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_show_create_db");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ mysqld_show_create_db_get_fields(thd, &fields);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
@@ -2186,8 +2203,14 @@ static bool check_prepared_statement(Prepared_statement *stmt)
res= mysql_test_create_table(stmt);
break;
case SQLCOM_SHOW_CREATE:
- res= mysql_test_show_create_table(stmt, tables);
- if (res == 2)
+ if (!(res= mysql_test_show_create_table(stmt, tables)))
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+ case SQLCOM_SHOW_CREATE_DB:
+ if (!(res= mysql_test_show_create_db(stmt)))
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);