用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

479 lines
13 KiB

5 months ago
# Test file for stored procedure bugfixes
--echo #
--echo # Bug #47412: Valgrind warnings / user can read uninitalized memory
--echo # using SP variables
--echo #
CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
RETURN f_not_exists () ;
END|
CREATE PROCEDURE p3 ( arg1 VARCHAR(32) )
BEGIN
CALL p_not_exists ( );
END|
DELIMITER ;|
--echo # should not return valgrind warnings
--error ER_SP_DOES_NOT_EXIST
CALL p3 ( f2 () );
DROP SCHEMA testdb;
CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
RETURN f_not_exists () ;
END|
CREATE PROCEDURE p3 ( arg2 INTEGER )
BEGIN
CALL p_not_exists ( );
END|
DELIMITER ;|
--echo # should not return valgrind warnings
--error ER_SP_DOES_NOT_EXIST
CALL p3 ( f2 () );
DROP SCHEMA testdb;
CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
RETURN f_not_exists () ;
END|
DELIMITER ;|
--echo # should not return valgrind warnings
SELECT f2 ();
DROP SCHEMA testdb;
USE test;
--echo #
--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP TRIGGER IF EXISTS tr1;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings
CREATE TABLE t1 (f1 INTEGER);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
CREATE PROCEDURE p1 () DROP TRIGGER tr1;
CALL p1 ();
--error ER_TRG_DOES_NOT_EXIST
CALL p1 ();
DROP TABLE t1;
DROP PROCEDURE p1;
--echo #
--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP TRIGGER IF EXISTS tr1;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings
CREATE TABLE t1 (f1 INTEGER);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
CREATE PROCEDURE p1 () DROP TRIGGER tr1;
CALL p1 ();
--error ER_TRG_DOES_NOT_EXIST
CALL p1 ();
DROP TABLE t1;
DROP PROCEDURE p1;
--echo #
--echo # Bug#54375: Error in stored procedure leaves connection
--echo # in different default schema
--echo #
--disable_warnings
SET @@SQL_MODE = 'STRICT_ALL_TABLES';
DROP DATABASE IF EXISTS db1;
CREATE DATABASE db1;
USE db1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 int NOT NULL PRIMARY KEY);
INSERT INTO t1 VALUES (1);
DELIMITER $$;
CREATE FUNCTION f1 (
some_value int
)
RETURNS smallint
DETERMINISTIC
BEGIN
INSERT INTO t1 SET c1 = some_value;
RETURN(LAST_INSERT_ID());
END$$
DELIMITER ;$$
DROP DATABASE IF EXISTS db2;
CREATE DATABASE db2;
--enable_warnings
USE db2;
SELECT DATABASE();
--error ER_DUP_ENTRY
SELECT db1.f1(1);
SELECT DATABASE();
USE test;
DROP FUNCTION db1.f1;
DROP TABLE db1.t1;
DROP DATABASE db1;
DROP DATABASE db2;
--echo #
--echo # Bug#13105873:valgrind warning:possible crash in foreign
--echo # key handling on subsequent create table if not exists
--echo #
--disable_warnings
DROP DATABASE IF EXISTS testdb;
--enable_warnings
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE t1 (id1 INT PRIMARY KEY);
DELIMITER $;
CREATE PROCEDURE `p1`()
BEGIN
CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY,
CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 ));
END$
DELIMITER ;$
CALL p1();
--echo # below stmt should not return valgrind warnings
CALL p1();
DROP DATABASE testdb;
USE test;
--echo End of 5.1 tests
--echo #
--echo # BUG#13489996 valgrind:conditional jump or move depends on
--echo # uninitialised values-field_blob
--echo #
CREATE FUNCTION sf() RETURNS BLOB RETURN "";
SELECT sf();
DROP FUNCTION sf;
--echo #
--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
--echo #
SET @@SQL_MODE = '';
DELIMITER $;
CREATE FUNCTION testf_bug11763507() RETURNS INT
BEGIN
RETURN 0;
END
$
CREATE PROCEDURE testp_bug11763507()
BEGIN
SELECT "PROCEDURE testp_bug11763507";
END
$
DELIMITER ;$
# STORED FUNCTIONS
SELECT testf_bug11763507();
SELECT TESTF_bug11763507();
--replace_column 5 # 6 #
SHOW FUNCTION STATUS LIKE 'testf_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS WHERE NAME='testf_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS LIKE 'TESTF_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS WHERE NAME='TESTF_bug11763507';
SHOW CREATE FUNCTION testf_bug11763507;
SHOW CREATE FUNCTION TESTF_bug11763507;
# STORED PROCEDURE
CALL testp_bug11763507();
CALL TESTP_bug11763507();
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS LIKE 'testp_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS WHERE NAME='testp_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS LIKE 'TESTP_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS WHERE NAME='TESTP_bug11763507';
SHOW CREATE PROCEDURE testp_bug11763507;
SHOW CREATE PROCEDURE TESTP_bug11763507;
# INFORMATION SCHEMA
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507';
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507';
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507';
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507';
DROP PROCEDURE testp_bug11763507;
DROP FUNCTION testf_bug11763507;
--echo #END OF BUG#11763507 test.
--echo #
--echo # Bug#19418619 : SELECT QUERY WITH INVALID TIME WORKS FINE BUT SP FAILS UNDER STRICT MODE
--echo #
SET sql_mode='NO_ENGINE_SUBSTITUTION';
# Create SF without STRICT mode
delimiter |;
CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT
BEGIN
RETURN abs('1abcd');
END|
delimiter ;|
SELECT f1(-25);
SELECT f1(25);
SET sql_mode=default;
# Passing invalid argument from STRICT mode gives error.
--error ER_WARN_DATA_OUT_OF_RANGE
SELECT f1(-25);
SELECT f1(10);
DROP FUNCTION f1;
SET sql_mode='NO_ENGINE_SUBSTITUTION';
# Create SP without STRICT mode
delimiter |;
CREATE PROCEDURE f1(IN arg TINYINT UNSIGNED)
BEGIN
DECLARE arg1 TINYINT;
select abs('1abcd') into arg;
END|
delimiter ;|
CALL f1(-25);
CALL f1(25);
SET sql_mode=default;
# Passing invalid argument from STRICT mode gives error.
--error ER_WARN_DATA_OUT_OF_RANGE
CALL f1(-25);
CALL f1(10);
DROP PROCEDURE f1;
# Select does not give error in STRICT mode
SELECT SUBTIME('2006-07-16' , '05:05:02.040778');
SELECT abs('1bcd');
# Create Stored Procedure in STRICT mode.
delimiter |;
CREATE PROCEDURE sp1()
BEGIN
SELECT SUBTIME('2006-07-16' , '05:05:02.040778');
END|
CREATE PROCEDURE sp2()
BEGIN
DECLARE v1 TINYINT DEFAULT 450000;
END|
delimiter ;|
CALL sp1();
--error ER_WARN_DATA_OUT_OF_RANGE
CALL sp2();
DROP PROCEDURE sp1;
DROP PROCEDURE sp2;
# Create Stored Function in STRICT mode
CREATE FUNCTION fn1(arg TINYINT UNSIGNED) RETURNS float deterministic RETURN abs('1abcd');
delimiter |;
CREATE FUNCTION fn2() RETURNS tinyint
BEGIN
DECLARE v1 TINYINT DEFAULT 450000;
RETURN v1;
END|
delimiter ;|
# On passing valid argument function execution fails as it was created in STRICT mode.
--error ER_TRUNCATED_WRONG_VALUE
SELECT fn1(25);
# Passing invalid argument from STRICT mode gives error for parameter evaluation.
--error ER_WARN_DATA_OUT_OF_RANGE
SELECT fn1(-25);
--error ER_WARN_DATA_OUT_OF_RANGE
SELECT fn2();
SET sql_mode='NO_ENGINE_SUBSTITUTION';
--error ER_TRUNCATED_WRONG_VALUE
SELECT fn1(-25);
DROP FUNCTION fn1;
DROP FUNCTION fn2;
#Create a function without STRICT mode
CREATE FUNCTION fn1() RETURNS float deterministic RETURN floor('1.1a');
# Create a function and Trigger in STRICT mode
SET sql_mode=default;
CREATE TABLE t1(a INT);
CREATE FUNCTION fn2() RETURNS float deterministic RETURN floor('1.1a');
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @a=fn2();
#Error expected as function call returns error
--error ER_TRUNCATED_WRONG_VALUE
INSERT INTO t1 VALUES(1);
DROP TRIGGER tr1;
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @a=fn1();
#No error as function call will not give error
INSERT INTO t1 VALUES(1);
DROP FUNCTION fn1;
DROP FUNCTION fn2;
DROP TRIGGER tr1;
DROP TABLE t1;
# Test for 'division by zero'
SET sql_mode=traditional;
# select passes
SELECT 1/0;
SET sql_mode='';
delimiter |;
CREATE PROCEDURE proc_c()
BEGIN
DECLARE div_zero INTEGER;
SET SQL_MODE='TRADITIONAL';
SELECT 1/0;
END|
delimiter ;|
# Procedure call passes.
CALL proc_c();
DROP PROCEDURE proc_c;
#check for SET command inside SF in TRADITIONAL mode
SET sql_mode=traditional;
delimiter |;
CREATE FUNCTION fn1() RETURNS TINYINT
BEGIN
SET @x=floor('1a');
RETURN 1;
END|
delimiter ;|
SELECT fn1();
DROP FUNCTION fn1;
SET sql_mode= default;
--echo #
--echo # Bug#24401273: PROBLEM WITH STORED FUNCTION WHICH GENERATES
--echo # BIGINT UNSIGNED USED IN WHERE CLAUSE
--echo #
--echo # Note: The AND TRUE is to work around Bug #24457368.
--echo #
CREATE FUNCTION crc(_text TEXT) RETURNS BIGINT(20) UNSIGNED DETERMINISTIC
RETURN CONV(LEFT(MD5(_text),16),16,10);
CREATE TABLE t1 (
id bigint(20) UNSIGNED NOT NULL
);
INSERT INTO t1 (id) VALUES (crc('photos'));
INSERT INTO t1 (id) VALUES (crc('photos1'));
ALTER TABLE t1 ADD INDEX idx (id);
SELECT * FROM t1 FORCE INDEX (idx) WHERE (id = crc('photos')) AND TRUE;
SELECT * FROM t1 IGNORE INDEX (idx) WHERE (id = crc('photos')) AND TRUE;
DROP FUNCTION crc;
DROP TABLE t1;
--echo # Bug#25398451: Segmentation fault in prepare_inner() at sql_call.cc
CREATE TABLE t1(a INTEGER, b INTEGER);
DELIMITER |;
CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW
BEGIN
CALL proc(NEW.a,NEW.b);
END |
CREATE PROCEDURE proc(IN aa INTEGER)
BEGIN
END |
DELIMITER ;|
--error ER_SP_WRONG_NO_OF_ARGS
INSERT INTO t1 VALUES (1,10);
DROP PROCEDURE proc;
DROP TABLE t1;
--echo #
--echo # Bug#28122841 - CREATE EVENT/PROCEDURE/FUNCTION CRASHES WITH ACCENT INSENSITIVE NAMES.
--echo #
SET NAMES utf8;
--echo #
--echo # Test case to verify stored procedure with case and accent insensitive names.
--echo #
CREATE PROCEDURE cafe() BEGIN END;
--echo # Stored procedure names are case and accent insensitive. So from the
--echo # data-dictionary "cafe" is obtained for the following statement. Since
--echo # MDL key comparison is case and accent sensitive, assert condition to verify
--echo # expected lock with name "test.cafe" fails (lock is obtained on the
--echo # test.café).
--error ER_SP_ALREADY_EXISTS
CREATE PROCEDURE café() BEGIN END;
--echo # Following statement is to verify operation with the upper case name.
--error ER_SP_ALREADY_EXISTS
CREATE PROCEDURE CAFE() BEGIN END;
DROP PROCEDURE CaFé;
--echo # Procedure with NAME_LEN size name.
CREATE PROCEDURE очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_e() BEGIN END;
--error ER_SP_ALREADY_EXISTS
CREATE PROCEDURE очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é() BEGIN END;
--error ER_SP_ALREADY_EXISTS
CREATE PROCEDURE очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_E() BEGIN END;
SHOW CREATE PROCEDURE очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é;
DROP PROCEDURE очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é;
--echo #
--echo # Test case to verify stored function with case and accent insensitive names.
--echo #
CREATE FUNCTION cafe() RETURNS INT return 15081947;
--echo # Stored function names are case and accent insensitive. So from the
--echo # data-dictionary "cafe" is obtained for the following statement. Since
--echo # MDL key comparison is case and accent sensitive, assert condition to verify
--echo # expected lock with name "test.cafe" fails (lock is obtained on the
--echo # test.café).
--error ER_SP_ALREADY_EXISTS
CREATE FUNCTION café() RETURNS INT return 15081947;
--echo # Following statement is to verify operation with the upper case name.
--error ER_SP_ALREADY_EXISTS
CREATE FUNCTION CAFE() RETURNS INT return 15081947;
--replace_column 2 # 3 # 4 # 5 # 6 #
SHOW CREATE FUNCTION CaFé;
DROP FUNCTION CaFé;
--echo # Function with NAME_LEN size name.
CREATE FUNCTION очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_e() RETURNS INT return 15081947;
--error ER_SP_ALREADY_EXISTS
CREATE FUNCTION очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é() RETURNS INT return 15081947;
--error ER_SP_ALREADY_EXISTS
CREATE FUNCTION очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_E() RETURNS INT return 15081947;
--replace_column 2 # 3 # 4 # 5 # 6 #
SHOW CREATE FUNCTION очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é;
DROP FUNCTION очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_é;
SET NAMES default;