Fix a problem causing the recovery extension to use excessive memory and CPU time...
[sqlite.git] / test / subtype1.test
blob4d8e68e6af7687dcab028620228809d8855d7116
1 # 2015-09-10
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
6 #    May you do good and not evil.
7 #    May you find forgiveness for yourself and forgive others.
8 #    May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements tests for sqlite3_value_subtype() and
12 # sqlite3_result_subtype() interfaces.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 do_execsql_test subtype1-100 {
19   SELECT test_getsubtype('hello');
20 } {0}
21 do_execsql_test subtype1-110 {
22   SELECT test_getsubtype(test_setsubtype('hello',123));
23 } {123}
24 do_execsql_test subtype1-120 {
25   SELECT typeof(test_setsubtype('hello',123));
26 } {text}
27 do_execsql_test subtype1-130 {
28   SELECT test_setsubtype('hello',123);
29 } {hello}
31 # 2022-06-09
32 # https://sqlite.org/forum/forumpost/3d9caa45cbe38c78
34 # Avoid carrying subtypes through into a subquery that has been flattened
35 # or to which the outer WHERE clause has been pushed down.
37 reset_db
38 do_execsql_test subtype1-200 {
39   CREATE TABLE t1(a); INSERT INTO t1 VALUES ('x');
40   CREATE VIEW t2(b) AS SELECT json(TRUE);
41   CREATE TABLE t3(b); INSERT INTO t3 VALUES(json(TRUE));
43 do_execsql_test subtype1-210 {
44   SELECT * FROM t3, t1 WHERE NOT json_quote(b);
45 } {1 x}
46 do_execsql_test subtype1-220 {
47   SELECT * FROM t2, t1 WHERE NOT json_quote(b);
48 } {1 x}
49 do_execsql_test subtype1-230 {
50   WITH t4(a) AS MATERIALIZED (SELECT json(1)) SELECT subtype(a) FROM t4;
51 } {0}
52 do_execsql_test subtype1-231 {
53   WITH t4(a) AS NOT MATERIALIZED (SELECT json(1)) SELECT subtype(a) FROM t4;
54 } {0}
56 # 2023-03-01
57 # https://sqlite.org/forum/forumpost/37dd14a538
58
59 # Additional tests to show that subtypes do not traverse subquery boundaries.
61 do_execsql_test subtype1-300 {
62   CREATE TABLE t0(c0);
63   INSERT INTO t0 VALUES ('1');
64   CREATE VIEW v0(c0) AS SELECT CASE WHEN 1 THEN json_patch('1', '1') END 
65                         FROM t0 GROUP BY t0.c0;
66   SELECT * FROM v0 WHERE json_quote(v0.c0) != '1';
67 } {1}
68 do_execsql_test subtype1-310 {
69   SELECT *, json_quote(y) FROM (SELECT +json('1') AS y);
70 } {1 {"1"}}
71 do_execsql_test subtype1-320 {
72   SELECT *, json_quote(y) FROM (SELECT +json('1') AS y)
73    WHERE json_quote(y)='"1"';
74 } {1 {"1"}}
77 finish_test