2019-01-23 19:59:24 +03:00
|
|
|
# 2019 January 23
|
|
|
|
#
|
|
|
|
# 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 altertab3
|
|
|
|
|
|
|
|
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
|
|
|
ifcapable !altertable {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:20:42 +03:00
|
|
|
|
2019-02-11 14:34:01 +03:00
|
|
|
ifcapable windowfunc {
|
2019-01-23 19:59:24 +03:00
|
|
|
do_execsql_test 1.0 {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
|
|
|
SELECT sum(b) OVER w FROM t1 WINDOW w AS (ORDER BY a);
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 1.1 {
|
|
|
|
ALTER TABLE t1 RENAME a TO aaa;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 1.2 {
|
|
|
|
SELECT sql FROM sqlite_master WHERE name='tr1'
|
|
|
|
} {{CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
|
|
|
SELECT sum(b) OVER w FROM t1 WINDOW w AS (ORDER BY aaa);
|
|
|
|
END}}
|
|
|
|
|
|
|
|
do_execsql_test 1.3 {
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
}
|
2019-02-11 14:34:01 +03:00
|
|
|
} ;# windowfunc
|
2019-01-23 19:59:24 +03:00
|
|
|
|
2019-01-23 22:50:46 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 2.0 {
|
|
|
|
CREATE TABLE t1(a,b,c);
|
|
|
|
CREATE TABLE t2(a,b,c);
|
|
|
|
CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
|
|
|
|
SELECT a,b, a name FROM t1
|
|
|
|
INTERSECT
|
|
|
|
SELECT a,b,c FROM t1 WHERE b>='d' ORDER BY name;
|
|
|
|
SELECT new.c;
|
|
|
|
END;
|
|
|
|
}
|
2019-01-23 19:59:24 +03:00
|
|
|
|
2019-01-23 22:50:46 +03:00
|
|
|
do_execsql_test 2.1 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
SELECT sql FROM sqlite_master WHERE name = 'r1';
|
|
|
|
} {{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN
|
|
|
|
SELECT a,b, a name FROM "t1x"
|
|
|
|
INTERSECT
|
|
|
|
SELECT a,b,c FROM "t1x" WHERE b>='d' ORDER BY name;
|
|
|
|
SELECT new.c;
|
|
|
|
END}}
|
2019-01-24 19:27:10 +03:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 3.0 {
|
|
|
|
CREATE TABLE t1(a, b, c, d);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ());
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 3.1 {
|
|
|
|
ALTER TABLE t1 RENAME b TO bbb;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 3.2 {
|
|
|
|
SELECT sql FROM sqlite_master WHERE name = 'v1'
|
2019-06-10 22:17:37 +03:00
|
|
|
} {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ())}}
|
2019-01-24 19:27:10 +03:00
|
|
|
|
2019-03-15 19:17:32 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 4.0 {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
CREATE TABLE t3(e, f);
|
|
|
|
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
|
|
|
INSERT INTO t2 VALUES(new.a, new.b);
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_catchsql_test 4.1.2 {
|
|
|
|
BEGIN;
|
|
|
|
ALTER TABLE t3 RENAME TO t4;
|
|
|
|
} {1 {error in trigger tr1: no such table: main.t2}}
|
|
|
|
do_execsql_test 4.1.2 {
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
do_execsql_test 4.1.3 {
|
2019-04-12 15:10:03 +03:00
|
|
|
SELECT type, name, tbl_name, sql
|
|
|
|
FROM sqlite_master WHERE type='table' AND name!='t1';
|
|
|
|
} {table t3 t3 {CREATE TABLE t3(e, f)}}
|
2019-01-24 19:27:10 +03:00
|
|
|
|
|
|
|
|
2019-03-15 19:17:32 +03:00
|
|
|
do_catchsql_test 4.2.1 {
|
|
|
|
BEGIN;
|
|
|
|
ALTER TABLE t3 RENAME e TO eee;
|
|
|
|
} {1 {error in trigger tr1: no such table: main.t2}}
|
|
|
|
do_execsql_test 4.2.2 {
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
do_execsql_test 4.2.3 {
|
2019-04-12 15:10:03 +03:00
|
|
|
SELECT type, name, tbl_name, sql
|
|
|
|
FROM sqlite_master WHERE type='table' AND name!='t1';
|
|
|
|
} {table t3 t3 {CREATE TABLE t3(e, f)}}
|
2019-03-15 19:17:32 +03:00
|
|
|
|
2019-03-20 19:58:21 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 5.0 {
|
|
|
|
CREATE TABLE t1 (
|
|
|
|
c1 integer, c2, PRIMARY KEY(c1 collate rtrim),
|
|
|
|
UNIQUE(c2)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
do_execsql_test 5.1 {
|
|
|
|
ALTER TABLE t1 RENAME c1 TO c3;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 6.0 {
|
|
|
|
CREATE TEMPORARY TABLE Table0 (
|
|
|
|
Col0 INTEGER,
|
|
|
|
PRIMARY KEY(Col0 COLLATE RTRIM),
|
|
|
|
FOREIGN KEY (Col0) REFERENCES Table0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 6.1 {
|
|
|
|
ALTER TABLE Table0 RENAME Col0 TO Col0;
|
|
|
|
}
|
|
|
|
|
2019-04-29 14:27:58 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 7.1.0 {
|
|
|
|
CREATE TABLE t1(a,b,c);
|
|
|
|
CREATE TRIGGER AFTER INSERT ON t1 BEGIN
|
|
|
|
SELECT a, rank() OVER w1 FROM t1
|
|
|
|
WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1);
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 7.1.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
SELECT sql FROM sqlite_master;
|
|
|
|
} {
|
|
|
|
{CREATE TABLE "t1x"(a,b,c)}
|
|
|
|
{CREATE TRIGGER AFTER INSERT ON "t1x" BEGIN
|
|
|
|
SELECT a, rank() OVER w1 FROM "t1x"
|
|
|
|
WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1);
|
|
|
|
END}
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 7.2.1 {
|
|
|
|
DROP TRIGGER after;
|
|
|
|
CREATE TRIGGER AFTER INSERT ON t1x BEGIN
|
|
|
|
SELECT a, rank() OVER w1 FROM t1x
|
|
|
|
WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1 ORDER BY d);
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_catchsql_test 7.2.2 {
|
|
|
|
ALTER TABLE t1x RENAME TO t1;
|
|
|
|
} {1 {error in trigger AFTER: no such column: d}}
|
|
|
|
|
2019-06-10 18:34:16 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 8.0 {
|
|
|
|
CREATE TABLE t0(c0);
|
|
|
|
CREATE INDEX i0 ON t0('1' IN ());
|
|
|
|
}
|
|
|
|
do_execsql_test 8.1 {
|
|
|
|
ALTER TABLE t0 RENAME TO t1;
|
|
|
|
SELECT sql FROM sqlite_master;
|
|
|
|
} {
|
|
|
|
{CREATE TABLE "t1"(c0)}
|
|
|
|
{CREATE INDEX i0 ON "t1"('1' IN ())}
|
|
|
|
}
|
2019-06-10 22:17:37 +03:00
|
|
|
do_execsql_test 8.2.1 {
|
|
|
|
CREATE TABLE t2 (c0);
|
|
|
|
CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()));
|
|
|
|
ALTER TABLE t2 RENAME COLUMN c0 TO c1;
|
|
|
|
}
|
|
|
|
do_execsql_test 8.2.2 {
|
|
|
|
SELECT sql FROM sqlite_master WHERE tbl_name = 't2';
|
|
|
|
} {
|
|
|
|
{CREATE TABLE t2 (c1)}
|
|
|
|
{CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()))}
|
|
|
|
}
|
|
|
|
do_test 8.2.3 {
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
db2 eval { INSERT INTO t2 VALUES (1), (2), (3) }
|
|
|
|
db close
|
|
|
|
} {}
|
2019-06-13 16:52:46 +03:00
|
|
|
db2 close
|
2019-06-10 22:17:37 +03:00
|
|
|
|
2019-06-11 15:03:10 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 9.1 {
|
|
|
|
CREATE TABLE t1(a,b,c);
|
|
|
|
CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
|
|
|
|
SELECT true WHERE (SELECT a, b FROM (t1)) IN ();
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
do_execsql_test 9.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
}
|
2019-06-10 22:17:37 +03:00
|
|
|
|
2019-06-15 18:27:37 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 10.1 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
CREATE TABLE t2(a, b, c);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE (
|
|
|
|
SELECT t1.a FROM t1, t2
|
|
|
|
) IN () OR t1.a=5;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 10.2 {
|
|
|
|
ALTER TABLE t2 RENAME TO t3;
|
|
|
|
SELECT sql FROM sqlite_master WHERE name='v1';
|
|
|
|
} {
|
|
|
|
{CREATE VIEW v1 AS SELECT * FROM t1 WHERE (
|
|
|
|
SELECT t1.a FROM t1, t2
|
|
|
|
) IN () OR t1.a=5}
|
|
|
|
}
|
|
|
|
|
2019-07-19 13:31:29 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 11.1 {
|
|
|
|
CREATE TABLE t1(
|
|
|
|
a,b,c,d,e,f,g,h,j,jj,jjb,k,aa,bb,cc,dd,ee DEFAULT 3.14,
|
|
|
|
ff DEFAULT('hiccup'),Wg NOD NULL DEFAULT(false)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN
|
|
|
|
SELECT a, sum() w3 FROM t1
|
|
|
|
WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM abc));
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_catchsql_test 11.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
} {1 {error in trigger b: no such table: abc}}
|
|
|
|
|
|
|
|
do_execsql_test 11.3 {
|
|
|
|
DROP TRIGGER b;
|
|
|
|
CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN
|
|
|
|
SELECT a, sum() w3 FROM t1
|
|
|
|
WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM t1));
|
|
|
|
END;
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_execsql_test 11.4 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
SELECT sql FROM sqlite_master WHERE name = 'b';
|
|
|
|
} {
|
|
|
|
{CREATE TRIGGER b AFTER INSERT ON "t1x" WHEN new.a BEGIN
|
|
|
|
SELECT a, sum() w3 FROM "t1x"
|
|
|
|
WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM "t1x"));
|
|
|
|
END}
|
|
|
|
}
|
2019-06-10 18:34:16 +03:00
|
|
|
|
2019-07-19 14:20:42 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 12.1 {
|
|
|
|
CREATE TABLE t1(a,b,c,d,e,f,g,h,j,jj,Zjj,k,aQ,bb,cc,dd,ee DEFAULT 3.14,
|
|
|
|
ff DEFAULT('hiccup'),gg NOD NULL DEFAULT(false));
|
|
|
|
CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
|
|
|
|
|
|
|
|
SELECT b () OVER , dense_rank() OVER d, d () OVER w1
|
|
|
|
FROM t1
|
|
|
|
WINDOW
|
|
|
|
w1 AS
|
|
|
|
( w1 ORDER BY d
|
|
|
|
ROWS BETWEEN 2 NOT IN(SELECT a, sum(d) w2,max(d)OVER FROM t1
|
|
|
|
WINDOW
|
|
|
|
w1 AS
|
|
|
|
(PARTITION BY d
|
|
|
|
ROWS BETWEEN '' PRECEDING AND false FOLLOWING),
|
|
|
|
d AS
|
|
|
|
(PARTITION BY b ORDER BY d
|
|
|
|
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
|
|
|
|
) PRECEDING AND 1 FOLLOWING),
|
|
|
|
w2 AS
|
|
|
|
(PARTITION BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),
|
|
|
|
w3 AS
|
|
|
|
(PARTITION BY b ORDER BY d
|
|
|
|
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)
|
|
|
|
;
|
|
|
|
SELECT a, sum(d) w2,max(d)OVER FROM t1
|
|
|
|
WINDOW
|
|
|
|
w1 AS
|
|
|
|
(PARTITION BY d
|
|
|
|
ROWS BETWEEN '' PRECEDING AND false FOLLOWING),
|
|
|
|
d AS
|
|
|
|
(PARTITION BY b ORDER BY d
|
|
|
|
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
|
|
|
|
;
|
|
|
|
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 12.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
}
|
|
|
|
|
2019-07-19 17:32:42 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 13.1 {
|
|
|
|
CREATE TABLE t1(a);
|
|
|
|
CREATE TRIGGER r1 INSERT ON t1 BEGIN
|
|
|
|
SELECT a(*) OVER (ORDER BY (SELECT 1)) FROM t1;
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 13.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
}
|
|
|
|
|
2019-07-22 14:38:43 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 14.1 {
|
|
|
|
CREATE TABLE t1(a);
|
|
|
|
CREATE TABLE t2(b);
|
|
|
|
CREATE TRIGGER AFTER INSERT ON t1 BEGIN
|
|
|
|
SELECT sum() FILTER (WHERE (SELECT sum() FILTER (WHERE 0)) AND a);
|
|
|
|
END;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_catchsql_test 14.2 {
|
|
|
|
ALTER TABLE t1 RENAME TO t1x;
|
|
|
|
} {1 {error in trigger AFTER: no such column: a}}
|
|
|
|
|
2019-01-23 19:59:24 +03:00
|
|
|
finish_test
|
2019-07-22 14:38:43 +03:00
|
|
|
|