Commit 9c8c1817 authored by andrey@example.com's avatar andrey@example.com

Fix for bug #20665 All commands supported in Stored Procedures

should work in Prepared Statements. Post-review changeset.

Problem: There are some commands which are avaiable to be executed in SP
         but cannot be prepared. This patch fixes this and makes it possible
         prepare these statements.

Changes: The commands later are made available in PS. RESET has been forbidden
         in SF/Trigger.

Solution: All current server commands where checked and those missing (see later)
          we added. Tests for all of the commands with repeated executions were
          added - testing with SP, SF and PS.

SHOW BINLOG EVENTS
SHOW (MASTER | SLAVE) STATUS
SHOW (MASTER | BINARY) LOGS
SHOW (PROCEDURE | FUNCTION) CODE (parsable only in debug builds)
SHOW CREATE (PROCEDURE | FUNCTION | EVENT | TABLE | VIEW)
SHOW (AUTHORS | CONTRIBUTORS | WARNINGS | ERRORS)
CHANGE MASTER
RESET (MASTER | SLAVE | QUERY CACHE)
SLAVE (START | STOP)
CHECKSUM (TABLE | TABLES)
INSTALL PLUGIN
UNINSTALL PLUGIN
CACHE INDEX
LOAD INDEX INTO CACHE
GRANT
REVOKE
KILL
(CREATE | RENAME | DROP) DATABASE
(CREATE | RENAME | DROP) USER
FLUSH (TABLE | TABLES | TABLES WITH READ LOCK | HOSTS | PRIVILEGES |
       LOGS | STATUS | MASTER | SLAVE | DES_KEY_FILE | USER_RESOURCES)
parent 30b4a459
This diff is collapsed.
......@@ -308,17 +308,11 @@ prepare stmt4 from ' show engine bdb logs ';
execute stmt4;
prepare stmt4 from ' show grants for user ';
prepare stmt4 from ' show create table t2 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show master status ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show master logs ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show slave status ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show warnings limit 20 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show errors limit 20 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show storage engines ';
execute stmt4;
drop table if exists t5;
......@@ -387,10 +381,8 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
prepare stmt4 from ' use test ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt3 from ' create database mysqltest ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
create database mysqltest ;
prepare stmt3 from ' drop database mysqltest ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
drop database mysqltest ;
prepare stmt3 from ' describe t2 ';
execute stmt3;
......@@ -412,7 +404,6 @@ execute stmt1 ;
prepare stmt1 from ' optimize table t1 ' ;
prepare stmt1 from ' analyze table t1 ' ;
prepare stmt1 from ' checksum table t1 ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' repair table t1 ' ;
prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
......@@ -440,11 +431,8 @@ execute stmt5;
1
SET sql_mode="";
prepare stmt1 from ' flush local privileges ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' reset query cache ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' KILL 0 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' explain select a from t1 order by b ';
execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
......
......@@ -78,13 +78,10 @@ ERROR 42000: There is no such grant defined for user 'second_user' on host 'loca
drop database mysqltest;
prepare stmt3 from ' grant all on test.t1 to drop_user@localhost
identified by ''looser'' ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
grant all on test.t1 to drop_user@localhost
identified by 'looser' ;
prepare stmt3 from ' revoke all privileges on test.t1 from
drop_user@localhost ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
revoke all privileges on test.t1 from drop_user@localhost ;
prepare stmt3 from ' drop user drop_user@localhost ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
drop user drop_user@localhost;
......@@ -284,11 +284,11 @@ call p1()|
select * from t1|
id stmt_text status
1 select 1 supported
2 flush tables not supported
2 flush tables supported
3 handler t1 open as ha not supported
4 analyze table t1 supported
5 check table t1 not supported
6 checksum table t1 not supported
6 checksum table t1 supported
7 check table t1 not supported
8 optimize table t1 supported
9 repair table t1 supported
......
This diff is collapsed.
......@@ -330,17 +330,11 @@ prepare stmt4 from ' show engine bdb logs ';
execute stmt4;
--enable_result_log
prepare stmt4 from ' show grants for user ';
--error 1295
prepare stmt4 from ' show create table t2 ';
--error 1295
prepare stmt4 from ' show master status ';
--error 1295
prepare stmt4 from ' show master logs ';
--error 1295
prepare stmt4 from ' show slave status ';
--error 1295
prepare stmt4 from ' show warnings limit 20 ';
--error 1295
prepare stmt4 from ' show errors limit 20 ';
prepare stmt4 from ' show storage engines ';
# The output depends upon the precise order in which
......@@ -427,14 +421,12 @@ prepare stmt1 from ' execute stmt2 ' ;
prepare stmt1 from ' deallocate prepare never_prepared ' ;
## switch the database connection
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt4 from ' use test ' ;
## create/drop database
--error 1295
prepare stmt3 from ' create database mysqltest ';
create database mysqltest ;
--error 1295
prepare stmt3 from ' drop database mysqltest ';
drop database mysqltest ;
......@@ -446,12 +438,12 @@ drop table t2 ;
--error 1146
execute stmt3;
## lock/unlock
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt3 from ' lock tables t1 read ' ;
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt3 from ' unlock tables ' ;
## Load/Unload table contents
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' load data infile ''data.txt''
into table t1 fields terminated by ''\t'' ';
prepare stmt1 from ' select * into outfile ''data.txt'' from t1 ';
......@@ -459,13 +451,12 @@ execute stmt1 ;
##
prepare stmt1 from ' optimize table t1 ' ;
prepare stmt1 from ' analyze table t1 ' ;
--error 1295
prepare stmt1 from ' checksum table t1 ' ;
prepare stmt1 from ' repair table t1 ' ;
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
## handler
--error 1295
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' handler t1 open ';
......@@ -491,11 +482,8 @@ SET sql_mode=ansi;
execute stmt5;
SET sql_mode="";
--error 1295
prepare stmt1 from ' flush local privileges ' ;
--error 1295
prepare stmt1 from ' reset query cache ' ;
--error 1295
prepare stmt1 from ' KILL 0 ';
## simple explain
......
......@@ -117,15 +117,12 @@ drop database mysqltest;
#
# grant/revoke + drop user
#
--error 1295
prepare stmt3 from ' grant all on test.t1 to drop_user@localhost
identified by ''looser'' ';
grant all on test.t1 to drop_user@localhost
identified by 'looser' ;
--error 1295
prepare stmt3 from ' revoke all privileges on test.t1 from
drop_user@localhost ';
revoke all privileges on test.t1 from drop_user@localhost ;
--error 1295
prepare stmt3 from ' drop user drop_user@localhost ';
drop user drop_user@localhost;
......@@ -161,17 +161,20 @@ sp_get_flags_for_command(LEX *lex)
}
/* fallthrough */
case SQLCOM_ANALYZE:
case SQLCOM_BACKUP_TABLE:
case SQLCOM_OPTIMIZE:
case SQLCOM_PRELOAD_KEYS:
case SQLCOM_ASSIGN_TO_KEYCACHE:
case SQLCOM_CHECKSUM:
case SQLCOM_CHECK:
case SQLCOM_HA_READ:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_BINLOGS:
case SQLCOM_SHOW_BINLOG_EVENTS:
case SQLCOM_SHOW_CHARSETS:
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_COLUMN_TYPES:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_SHOW_CREATE:
case SQLCOM_SHOW_CREATE_DB:
case SQLCOM_SHOW_CREATE_FUNC:
......@@ -180,16 +183,20 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_ERRORS:
case SQLCOM_SHOW_FIELDS:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_GRANTS:
case SQLCOM_SHOW_ENGINE_STATUS:
case SQLCOM_SHOW_ENGINE_LOGS:
case SQLCOM_SHOW_ENGINE_MUTEX:
case SQLCOM_SHOW_EVENTS:
case SQLCOM_SHOW_KEYS:
case SQLCOM_SHOW_MASTER_STAT:
case SQLCOM_SHOW_NEW_MASTER:
case SQLCOM_SHOW_OPEN_TABLES:
case SQLCOM_SHOW_PRIVILEGES:
case SQLCOM_SHOW_PROCESSLIST:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_SCHEDULER_STATUS:
case SQLCOM_SHOW_SLAVE_HOSTS:
case SQLCOM_SHOW_SLAVE_STAT:
case SQLCOM_SHOW_STATUS:
......@@ -199,12 +206,7 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_TABLES:
case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_WARNS:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_REPAIR:
case SQLCOM_BACKUP_TABLE:
case SQLCOM_RESTORE_TABLE:
flags= sp_head::MULTI_RESULTS;
break;
......@@ -262,6 +264,9 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_CREATE_EVENT:
case SQLCOM_ALTER_EVENT:
case SQLCOM_DROP_EVENT:
case SQLCOM_FLUSH:
case SQLCOM_INSTALL_PLUGIN:
case SQLCOM_UNINSTALL_PLUGIN:
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
break;
default:
......
......@@ -1740,6 +1740,20 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_SHOW_ENGINE_MUTEX:
case SQLCOM_SHOW_CREATE_DB:
case SQLCOM_SHOW_GRANTS:
case SQLCOM_SHOW_BINLOG_EVENTS:
case SQLCOM_SHOW_MASTER_STAT:
case SQLCOM_SHOW_SLAVE_STAT:
case SQLCOM_SHOW_CREATE_PROC:
case SQLCOM_SHOW_CREATE_FUNC:
case SQLCOM_SHOW_CREATE_EVENT:
case SQLCOM_SHOW_CREATE:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_SHOW_WARNS:
case SQLCOM_SHOW_ERRORS:
case SQLCOM_SHOW_BINLOGS:
case SQLCOM_DROP_TABLE:
case SQLCOM_RENAME_TABLE:
case SQLCOM_ALTER_TABLE:
......@@ -1754,6 +1768,25 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_REPAIR:
case SQLCOM_ANALYZE:
case SQLCOM_OPTIMIZE:
case SQLCOM_CHANGE_MASTER:
case SQLCOM_RESET:
case SQLCOM_FLUSH:
case SQLCOM_SLAVE_START:
case SQLCOM_SLAVE_STOP:
case SQLCOM_INSTALL_PLUGIN:
case SQLCOM_UNINSTALL_PLUGIN:
case SQLCOM_CREATE_DB:
case SQLCOM_DROP_DB:
case SQLCOM_RENAME_DB:
case SQLCOM_CHECKSUM:
case SQLCOM_CREATE_USER:
case SQLCOM_RENAME_USER:
case SQLCOM_DROP_USER:
case SQLCOM_ASSIGN_TO_KEYCACHE:
case SQLCOM_PRELOAD_KEYS:
case SQLCOM_GRANT:
case SQLCOM_REVOKE:
case SQLCOM_KILL:
break;
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment