mirror of
https://github.com/MariaDB/server.git
synced 2025-07-23 08:45:18 +03:00
297 lines
4.8 KiB
Plaintext
297 lines
4.8 KiB
Plaintext
SET sql_mode=ORACLE;
|
|
|
|
--echo #
|
|
--echo # MDEV-10582 sql_mode=ORACLE: explicit cursor attributes %ISOPEN, %ROWCOUNT, %FOUND, %NOTFOUND
|
|
--echo #
|
|
|
|
|
|
--echo #
|
|
--echo # Cursor attributes outside of an SP context
|
|
--echo #
|
|
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
SELECT c%ISOPEN;
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
SELECT c%FOUND;
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
SELECT c%NOTFOUND;
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
SELECT c%ROWCOUNT;
|
|
|
|
|
|
--echo #
|
|
--echo # Undefinite cursor attributes
|
|
--echo #
|
|
|
|
DELIMITER $$;
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
BEGIN
|
|
SELECT c%ISOPEN;
|
|
END;
|
|
$$
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
BEGIN
|
|
SELECT c%ROWCOUNT;
|
|
END;
|
|
$$
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
BEGIN
|
|
SELECT c%FOUND;
|
|
END;
|
|
$$
|
|
--error ER_SP_CURSOR_MISMATCH
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
BEGIN
|
|
SELECT c%NOTFOUND;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
|
|
|
|
--echo #
|
|
--echo # Not opened cursor attributes %FOUND, %NOTFOUND, %ROWCOUNT
|
|
--echo #
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%ROWCOUNT;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
--error ER_SP_CURSOR_NOT_OPEN
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%FOUND;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
--error ER_SP_CURSOR_NOT_OPEN
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%NOTFOUND;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
--error ER_SP_CURSOR_NOT_OPEN
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
|
|
--echo #
|
|
--echo # Not opened cursor attributes %FOUND, %NOTFOUND, %ROWCOUNT with INVALID_CURSOR exception
|
|
--echo #
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%ROWCOUNT;
|
|
EXCEPTION
|
|
WHEN INVALID_CURSOR THEN SELECT 'INVALID_CURSOR caught' AS msg;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%FOUND;
|
|
EXCEPTION
|
|
WHEN INVALID_CURSOR THEN SELECT 'INVALID_CURSOR caught' AS msg;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT 1 AS c FROM DUAL;
|
|
BEGIN
|
|
SELECT c%NOTFOUND;
|
|
EXCEPTION
|
|
WHEN INVALID_CURSOR THEN SELECT 'INVALID_CURSOR caught' AS msg;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1;
|
|
DROP PROCEDURE p1;
|
|
|
|
|
|
--echo #
|
|
--echo # print()
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT * FROM t1 ORDER BY a;
|
|
BEGIN
|
|
EXPLAIN EXTENDED SELECT c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo #
|
|
--echo # Declared data type of the attributes
|
|
--echo #
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (10);
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
CURSOR c IS SELECT * FROM t1 ORDER BY a;
|
|
BEGIN
|
|
OPEN c;
|
|
CREATE TABLE t2 AS SELECT c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
SHOW CREATE TABLE t2;
|
|
DROP TABLE t2;
|
|
CLOSE c;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo #
|
|
--echo # Core functionality
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (10);
|
|
INSERT INTO t1 VALUES (20);
|
|
INSERT INTO t1 VALUES (30);
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
a INT:=0;
|
|
CURSOR c IS SELECT * FROM t1 ORDER BY a;
|
|
BEGIN
|
|
SELECT a, c%ISOPEN;
|
|
OPEN c;
|
|
/*
|
|
After OPEN and before FETCH:
|
|
- %ROWCOUNT returns 0
|
|
- %FOUND and %NOTFOUND return NULL
|
|
*/
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
FETCH c INTO a;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
FETCH c INTO a;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
FETCH c INTO a;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
FETCH c INTO a;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
CLOSE c;
|
|
SELECT a, c%ISOPEN;
|
|
/*
|
|
After reopen and before FETCH:
|
|
- %ROWCOUNT returns 0
|
|
- %FOUND and %NOTFOUND return NULL
|
|
*/
|
|
OPEN c;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
FETCH c INTO a;
|
|
SELECT a, c%ISOPEN, c%ROWCOUNT, c%FOUND, c%NOTFOUND;
|
|
CLOSE c;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo #
|
|
--echo # %NOTFOUND as a loop exit condition
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (10);
|
|
INSERT INTO t1 VALUES (20);
|
|
INSERT INTO t1 VALUES (30);
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
a INT:=0;
|
|
CURSOR c IS SELECT * FROM t1 ORDER BY a;
|
|
BEGIN
|
|
OPEN c;
|
|
LOOP
|
|
FETCH c INTO a;
|
|
EXIT WHEN c%NOTFOUND;
|
|
SELECT a;
|
|
END LOOP;
|
|
CLOSE c;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo #
|
|
--echo # %FOUND as a loop exit condition
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (10);
|
|
INSERT INTO t1 VALUES (20);
|
|
INSERT INTO t1 VALUES (30);
|
|
DELIMITER $$;
|
|
CREATE PROCEDURE p1
|
|
AS
|
|
a INT:=0;
|
|
CURSOR c IS SELECT * FROM t1 ORDER BY a;
|
|
BEGIN
|
|
OPEN c;
|
|
LOOP
|
|
FETCH c INTO a;
|
|
EXIT WHEN NOT c%FOUND;
|
|
SELECT a;
|
|
END LOOP;
|
|
CLOSE c;
|
|
END;
|
|
$$
|
|
DELIMITER ;$$
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1;
|