#
# MDEV-20034 Add support for the pre-defined weak SYS_REFCURSOR
#
CREATE TABLE t1
(
a INT,
b INT AS (CURSOR_REF_COUNT(a)) STORED
);
ERROR HY000: Function or expression 'cursor_ref_count()' cannot be used in the GENERATED ALWAYS AS clause of `b`
CREATE TABLE t1
(
a INT,
b BOOLEAN AS (CURSOR_REF_COUNT(a) IS NULL) STORED
);
ERROR HY000: Function or expression 'cursor_ref_count()' cannot be used in the GENERATED ALWAYS AS clause of `b`
CREATE TABLE t1
(
a INT,
b INT AS (CURSOR_REF_COUNT(a)) VIRTUAL
);
INSERT INTO t1 (a) VALUES (0),(1),(2),(3),(4);
CREATE PROCEDURE p1()
BEGIN
DECLARE c0 SYS_REFCURSOR; -- uses m_statement_cursors.at(0) after OPEN c0
DECLARE c1 SYS_REFCURSOR; -- stays NULL
DECLARE c2 SYS_REFCURSOR; -- uses m_statement_cursors.at(1) after OPEN c2
DECLARE c3 SYS_REFCURSOR; -- uses m_statement_cursors.at(1) after c3=c2
OPEN c0 FOR SELECT 10;
OPEN c2 FOR SELECT 20;
SET c3= c2;
SELECT a, b FROM t1;
-- Make sure direct calls of CURSOR_REF_COUNT(n) return the same values
-- with the virtual column t1.b values in the previous SELECT.
SELECT
CURSOR_REF_COUNT(0) AS cnt0,
CURSOR_REF_COUNT(1) AS cnt1,
CURSOR_REF_COUNT(2) AS cnt2,
CURSOR_REF_COUNT(3) AS cnt3,
CURSOR_REF_COUNT(4) AS cnt4;
END;
/
CALL p1;
a	b
0	1
1	2
2	NULL
3	NULL
4	NULL
cnt0	cnt1	cnt2	cnt3	cnt4
1	2	NULL	NULL	NULL
DROP PROCEDURE p1;
DROP TABLE t1;
