sqlite/test/windowE.test
dan 58b08d7702 Avoid a stack overflow that could be caused by a recursively defined WINDOW() with a strategically embedded error.
FossilOrigin-Name: bada54bd6bf54190e40aa721b77081015957d204c7b6a9fdbe8c67bcf20798f8
2024-08-24 15:54:15 +00:00

79 lines
1.8 KiB
Plaintext

# 2022 October 18
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix windowE
proc custom {a b} { return [string compare $a $b] }
db collate custom custom
do_execsql_test 1.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT COLLATE custom);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t1 VALUES(4, 'four');
INSERT INTO t1 VALUES(5, 'five');
INSERT INTO t1 VALUES(6, 'six');
CREATE INDEX t1b ON t1(b);
}
do_execsql_test 1.1 {
SELECT * FROM t1
} {
1 one 2 two 3 three 4 four 5 five 6 six
}
do_execsql_test 1.2 {
SELECT group_concat(a,',') OVER win FROM t1
WINDOW win AS (
ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING
)
} {
5 4 1 6 3 2
}
proc custom {a b} { return [string compare $b $a] }
do_execsql_test 1.3 {
SELECT group_concat(a,',') OVER win FROM t1
WINDOW win AS (
ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING
)
} {
5 5,4 5,4,1 5,4,1,6 5,4,1,6,3 5,4,1,6,3,2
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(x);
}
sqlite3_create_aggregate db
breakpoint
do_catchsql_test 2.1 {
SELECT min(x) OVER w1 FROM t1
WINDOW w1 AS (PARTITION BY x_count(x) OVER w1);
} {1 {x_count() may not be used as a window function}}
do_catchsql_test 2.2 {
SELECT min(x) FILTER (WHERE x_count(x) OVER w1) OVER w1 FROM t1
WINDOW w1 AS (PARTITION BY x OVER w1);
} {1 {near "OVER": syntax error}}
finish_test