summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2016-02-06 18:14:54 +0200
committerMonty <monty@mariadb.org>2016-02-06 18:14:54 +0200
commitb2f8d7b41001a5da11b2d99a055a207c3911a213 (patch)
treed108ed6d1f38543305235fec6a63228a5a2f08d5 /sql/sql_prepare.cc
parentd4b3a199acb0ddcdedff441ae664b0a2cf2fe8d2 (diff)
parent07b8aefe90ca830d2de068f2966cd2288b158a88 (diff)
downloadmariadb-git-b2f8d7b41001a5da11b2d99a055a207c3911a213.tar.gz
Merge branch '10.1' into 10.2
Conflicts: VERSION cmake/plugin.cmake config.h.cmake configure.cmake plugin/server_audit/server_audit.c sql/sql_yacc.yy
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc249
1 files changed, 248 insertions, 1 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 809e6d63338..ca23e11676a 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -103,6 +103,9 @@ When one supplies long data for a placeholder:
#include "sql_derived.h" // mysql_derived_prepare,
// mysql_handle_derived
#include "sql_cursor.h"
+#include "sql_show.h"
+#include "sql_repl.h"
+#include "slave.h"
#include "sp_head.h"
#include "sp.h"
#include "sp_cache.h"
@@ -1799,6 +1802,191 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
}
+static int send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *fields)
+{
+ if (stmt->is_sql_prepare())
+ return 0;
+
+ if (send_prep_stmt(stmt, fields->elements) ||
+ thd->protocol->send_result_set_metadata(fields, Protocol::SEND_EOF) ||
+ thd->protocol->flush())
+ return 1;
+
+ return 2;
+}
+
+
+/**
+ Validate and prepare for execution SHOW CREATE TABLE statement.
+
+ @param stmt prepared statement
+ @param tables list of tables used in this query
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_create_table(Prepared_statement *stmt,
+ TABLE_LIST *tables)
+{
+ DBUG_ENTER("mysql_test_show_create_table");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+ char buff[2048];
+ String buffer(buff, sizeof(buff), system_charset_info);
+
+ if (mysqld_show_create_get_fields(thd, tables, &fields, &buffer))
+ DBUG_RETURN(1);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+
+
+/**
+ 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 int 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));
+}
+
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+/**
+ Validate and prepare for execution SHOW GRANTS statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_grants(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_show_grants");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ mysql_show_grants_get_fields(thd, &fields, "Grants for");
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
+
+
+#ifndef EMBEDDED_LIBRARY
+/**
+ Validate and prepare for execution SHOW SLAVE STATUS statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_slave_status(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_show_slave_status");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ show_master_info_get_fields(thd, &fields, 0, 0);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+
+
+/**
+ Validate and prepare for execution SHOW MASTER STATUS statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_master_status(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_show_master_status");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ show_binlog_info_get_fields(thd, &fields);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+
+
+/**
+ Validate and prepare for execution SHOW BINLOGS statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_binlogs(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_show_binlogs");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ show_binlogs_get_fields(thd, &fields);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+
+#endif /* EMBEDDED_LIBRARY */
+
+
+/**
+ Validate and prepare for execution SHOW CREATE PROC/FUNC statement.
+
+ @param stmt prepared statement
+
+ @retval
+ FALSE success
+ @retval
+ TRUE error, error message is set in THD
+*/
+
+static int mysql_test_show_create_routine(Prepared_statement *stmt, int type)
+{
+ DBUG_ENTER("mysql_test_show_binlogs");
+ THD *thd= stmt->thd;
+ List<Item> fields;
+
+ sp_head::show_create_routine_get_fields(thd, type, &fields);
+
+ DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
+}
+
+
/**
@brief Validate and prepare for execution CREATE VIEW statement
@@ -2132,7 +2320,66 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_CREATE_TABLE:
res= mysql_test_create_table(stmt);
break;
-
+ case SQLCOM_SHOW_CREATE:
+ if ((res= mysql_test_show_create_table(stmt, tables)) == 2)
+ {
+ /* 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)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ case SQLCOM_SHOW_GRANTS:
+ if ((res= mysql_test_show_grants(stmt)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+#endif /* NO_EMBEDDED_ACCESS_CHECKS */
+#ifndef EMBEDDED_LIBRARY
+ case SQLCOM_SHOW_SLAVE_STAT:
+ if ((res= mysql_test_show_slave_status(stmt)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+ case SQLCOM_SHOW_MASTER_STAT:
+ if ((res= mysql_test_show_master_status(stmt)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+ case SQLCOM_SHOW_BINLOGS:
+ if ((res= mysql_test_show_binlogs(stmt)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+#endif /* EMBEDDED_LIBRARY */
+ case SQLCOM_SHOW_CREATE_PROC:
+ if ((res= mysql_test_show_create_routine(stmt, TYPE_ENUM_PROCEDURE)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
+ case SQLCOM_SHOW_CREATE_FUNC:
+ if ((res= mysql_test_show_create_routine(stmt, TYPE_ENUM_FUNCTION)) == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ break;
case SQLCOM_CREATE_VIEW:
if (lex->create_view_mode == VIEW_ALTER)
{