summaryrefslogtreecommitdiffstats
path: root/third_party/sqlite/src/test/selectC.test
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/sqlite/src/test/selectC.test')
-rw-r--r--third_party/sqlite/src/test/selectC.test93
1 files changed, 81 insertions, 12 deletions
diff --git a/third_party/sqlite/src/test/selectC.test b/third_party/sqlite/src/test/selectC.test
index 10804a9..fd38405 100644
--- a/third_party/sqlite/src/test/selectC.test
+++ b/third_party/sqlite/src/test/selectC.test
@@ -151,17 +151,86 @@ do_test selectC-1.14.2 {
# The following query used to leak memory. Verify that has been fixed.
#
-do_test selectC-2.1 {
- catchsql {
- CREATE TABLE t21a(a,b);
- INSERT INTO t21a VALUES(1,2);
- CREATE TABLE t21b(n);
- CREATE TRIGGER r21 AFTER INSERT ON t21b BEGIN
- SELECT a FROM t21a WHERE a>new.x UNION ALL
- SELECT b FROM t21a WHERE b>new.x ORDER BY 1 LIMIT 2;
- END;
- INSERT INTO t21b VALUES(6);
- }
-} {1 {no such column: new.x}}
+ifcapable trigger {
+ do_test selectC-2.1 {
+ catchsql {
+ CREATE TABLE t21a(a,b);
+ INSERT INTO t21a VALUES(1,2);
+ CREATE TABLE t21b(n);
+ CREATE TRIGGER r21 AFTER INSERT ON t21b BEGIN
+ SELECT a FROM t21a WHERE a>new.x UNION ALL
+ SELECT b FROM t21a WHERE b>new.x ORDER BY 1 LIMIT 2;
+ END;
+ INSERT INTO t21b VALUES(6);
+ }
+ } {1 {no such column: new.x}}
+}
+
+# Check that ticket [883034dcb5] is fixed.
+#
+do_test selectC-3.1 {
+ execsql {
+ CREATE TABLE person (
+ org_id TEXT NOT NULL,
+ nickname TEXT NOT NULL,
+ license TEXT,
+ CONSTRAINT person_pk PRIMARY KEY (org_id, nickname),
+ CONSTRAINT person_license_uk UNIQUE (license)
+ );
+ INSERT INTO person VALUES('meyers', 'jack', '2GAT123');
+ INSERT INTO person VALUES('meyers', 'hill', 'V345FMP');
+ INSERT INTO person VALUES('meyers', 'jim', '2GAT138');
+ INSERT INTO person VALUES('smith', 'maggy', '');
+ INSERT INTO person VALUES('smith', 'jose', 'JJZ109');
+ INSERT INTO person VALUES('smith', 'jack', 'THX138');
+ INSERT INTO person VALUES('lakeside', 'dave', '953OKG');
+ INSERT INTO person VALUES('lakeside', 'amy', NULL);
+ INSERT INTO person VALUES('lake-apts', 'tom', NULL);
+ INSERT INTO person VALUES('acorn', 'hideo', 'CQB421');
+
+ SELECT
+ org_id,
+ count((NOT (org_id IS NULL)) AND (NOT (nickname IS NULL)))
+ FROM person
+ WHERE (CASE WHEN license != '' THEN 1 ELSE 0 END)
+ GROUP BY 1;
+ }
+} {acorn 1 lakeside 1 meyers 3 smith 2}
+do_test selectC-3.2 {
+ execsql {
+ CREATE TABLE t2(a PRIMARY KEY, b);
+ INSERT INTO t2 VALUES('abc', 'xxx');
+ INSERT INTO t2 VALUES('def', 'yyy');
+ SELECT a, max(b || a) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
+ }
+} {abc xxxabc def yyydef}
+do_test selectC-3.3 {
+ execsql {
+ SELECT b, max(a || b) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
+ }
+} {xxx abcxxx yyy defyyy}
+
+
+proc udf {} { incr ::udf }
+set ::udf 0
+db function udf udf
+
+do_execsql_test selectC-4.1 {
+ create table t_distinct_bug (a, b, c);
+ insert into t_distinct_bug values ('1', '1', 'a');
+ insert into t_distinct_bug values ('1', '2', 'b');
+ insert into t_distinct_bug values ('1', '3', 'c');
+ insert into t_distinct_bug values ('1', '1', 'd');
+ insert into t_distinct_bug values ('1', '2', 'e');
+ insert into t_distinct_bug values ('1', '3', 'f');
+} {}
+
+do_execsql_test selectC-4.2 {
+ select a from (select distinct a, b from t_distinct_bug)
+} {1 1 1}
+
+do_execsql_test selectC-4.3 {
+ select a, udf() from (select distinct a, b from t_distinct_bug)
+} {1 1 1 2 1 3}
finish_test