summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc68
1 files changed, 53 insertions, 15 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 951231537d8..5635d87de0c 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1724,6 +1724,13 @@ static bool check_prepared_statement(Prepared_statement *stmt,
res= mysql_test_create_table(stmt);
break;
+ case SQLCOM_CREATE_VIEW:
+ if (lex->create_view_mode == VIEW_ALTER)
+ {
+ my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0));
+ goto error;
+ }
+ break;
case SQLCOM_DO:
res= mysql_test_do_fields(stmt, tables, lex->insert_list);
break;
@@ -1766,7 +1773,6 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_ROLLBACK:
case SQLCOM_TRUNCATE:
case SQLCOM_CALL:
- case SQLCOM_CREATE_VIEW:
case SQLCOM_DROP_VIEW:
case SQLCOM_REPAIR:
case SQLCOM_ANALYZE:
@@ -1894,13 +1900,6 @@ void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length)
/* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt);
}
- else
- {
- const char *format= "[%lu] %.*b";
- mysql_log.write(thd, COM_STMT_PREPARE, format, stmt->id,
- stmt->query_length, stmt->query);
-
- }
/* check_prepared_statemnt sends the metadata packet in case of success */
DBUG_VOID_RETURN;
}
@@ -2286,13 +2285,6 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
test(flags & (ulong) CURSOR_TYPE_READ_ONLY));
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);
- if (error == 0)
- {
- const char *format= "[%lu] %.*b";
- mysql_log.write(thd, COM_STMT_EXECUTE, format, stmt->id,
- thd->query_length, thd->query);
- }
-
DBUG_VOID_RETURN;
set_params_data_err:
@@ -2823,6 +2815,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
lex_start(thd);
lex->safe_to_cache_query= FALSE;
int err= MYSQLparse((void *)thd);
+ lex->set_trg_event_type_for_tables();
error= err || thd->is_fatal_error ||
thd->net.report_error || init_param_array(this);
@@ -2875,6 +2868,29 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
init_stmt_after_parse(lex);
state= Query_arena::PREPARED;
flags&= ~ (uint) IS_IN_USE;
+
+ /*
+ Log COM_EXECUTE to the general log. Note, that in case of SQL
+ prepared statements this causes two records to be output:
+
+ Query PREPARE stmt from @user_variable
+ Prepare <statement SQL text>
+
+ This is considered user-friendly, since in the
+ second log entry we output the actual statement text.
+
+ Do not print anything if this is an SQL prepared statement and
+ we're inside a stored procedure (also called Dynamic SQL) --
+ sub-statements inside stored procedures are not logged into
+ the general log.
+ */
+ if (thd->spcont == NULL)
+ {
+ const char *format= "[%lu] %.*b";
+ mysql_log.write(thd, COM_STMT_PREPARE, format, id,
+ query_length, query);
+
+ }
}
DBUG_RETURN(error);
}
@@ -3012,6 +3028,28 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
if (state == Query_arena::PREPARED)
state= Query_arena::EXECUTED;
+ /*
+ Log COM_EXECUTE to the general log. Note, that in case of SQL
+ prepared statements this causes two records to be output:
+
+ Query EXECUTE <statement name>
+ Execute <statement SQL text>
+
+ This is considered user-friendly, since in the
+ second log entry we output values of parameter markers.
+
+ Do not print anything if this is an SQL prepared statement and
+ we're inside a stored procedure (also called Dynamic SQL) --
+ sub-statements inside stored procedures are not logged into
+ the general log.
+ */
+ if (error == 0 && thd->spcont == NULL)
+ {
+ const char *format= "[%lu] %.*b";
+ mysql_log.write(thd, COM_STMT_EXECUTE, format, id,
+ thd->query_length, thd->query);
+ }
+
error:
flags&= ~ (uint) IS_IN_USE;
return error;