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 #*************************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix altertab
17 # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
18 ifcapable !altertable {
24 CREATE TABLE t1(a, b, CHECK(t1.a != t1.b));
26 CREATE TABLE t2(a, b);
27 CREATE INDEX t2expr ON t2(a) WHERE t2.b>0;
31 SELECT sql FROM sqlite_master
33 {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))}
34 {CREATE TABLE t2(a, b)}
35 {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0}
39 ALTER TABLE t1 RENAME TO t1new;
43 CREATE TABLE t3(c, d);
44 ALTER TABLE t3 RENAME TO t3new;
49 SELECT sql FROM sqlite_master
51 {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))}
52 {CREATE TABLE t2(a, b)}
53 {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0}
58 ALTER TABLE t2 RENAME TO t2new;
61 SELECT sql FROM sqlite_master
63 {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))}
64 {CREATE TABLE "t2new"(a, b)}
65 {CREATE INDEX t2expr ON "t2new"(a) WHERE "t2new".b>0}
69 #-------------------------------------------------------------------------
72 register_echo_module db
75 CREATE TABLE abc(a, b, c);
76 INSERT INTO abc VALUES(1, 2, 3);
77 CREATE VIRTUAL TABLE eee USING echo('abc');
82 ALTER TABLE eee RENAME TO fff;
89 do_catchsql_test 2.2 {
90 ALTER TABLE fff RENAME TO ggg;
91 } {1 {no such module: echo}}
94 #-------------------------------------------------------------------------
98 CREATE TABLE txx(a, b, c);
99 INSERT INTO txx VALUES(1, 2, 3);
100 CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx;
101 CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one;
102 CREATE VIEW temp.ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx;
105 do_execsql_test 3.1.1 {
108 do_execsql_test 3.1.2 {
109 ALTER TABLE txx RENAME TO "t xx";
112 do_execsql_test 3.1.3 {
113 SELECT sql FROM sqlite_master WHERE name='vvv';
114 } {{CREATE VIEW vvv AS SELECT main."t xx".a, "t xx".b, c FROM "t xx"}}
117 do_execsql_test 3.2.1 {
120 do_execsql_test 3.2.2 {
121 SELECT sql FROM sqlite_master WHERE name='uuu';;
122 } {{CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM "t xx" AS one}}
124 do_execsql_test 3.3.1 {
127 do_execsql_test 3.3.2 {
128 SELECT sql FROM sqlite_temp_master WHERE name='ttt';
129 } {{CREATE VIEW ttt AS SELECT main."t xx".a, "t xx".b, one.b, main.one.a FROM "t xx" AS one, "t xx"}}
131 #-------------------------------------------------------------------------
133 do_execsql_test 4.0 {
134 CREATE table t1(x, y);
135 CREATE table t2(a, b);
137 CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
138 SELECT t1.x, * FROM t1, t2;
139 INSERT INTO t2 VALUES(new.x, new.y);
143 do_execsql_test 4.1 {
144 INSERT INTO t1 VALUES(1, 1);
145 ALTER TABLE t1 RENAME TO t11;
146 INSERT INTO t11 VALUES(2, 2);
147 ALTER TABLE t2 RENAME TO t22;
148 INSERT INTO t11 VALUES(3, 3);
152 string trim [regsub -all {[[:space:]][[:space:]]*} $a { }]
154 db func squish squish
156 execsql { SELECT squish(sql) FROM sqlite_master WHERE name = 'tr1' }
158 CREATE TRIGGER tr1 AFTER INSERT ON "t11" BEGIN
159 SELECT "t11".x, * FROM "t11", "t22";
160 INSERT INTO "t22" VALUES(new.x, new.y);
164 #-------------------------------------------------------------------------
166 do_execsql_test 5.0 {
167 CREATE TABLE t9(a, b, c);
168 CREATE TABLE t10(a, b, c);
169 CREATE TEMP TABLE t9(a, b, c);
171 CREATE TRIGGER temp.t9t AFTER INSERT ON temp.t9 BEGIN
172 INSERT INTO t10 VALUES(new.a, new.b, new.c);
175 INSERT INTO temp.t9 VALUES(1, 2, 3);
179 do_execsql_test 5.1 {
180 ALTER TABLE temp.t9 RENAME TO 't1234567890'
183 do_execsql_test 5.2 {
184 CREATE TABLE t1(a, b);
185 CREATE TABLE t2(a, b);
186 INSERT INTO t1 VALUES(1, 2);
187 INSERT INTO t2 VALUES(3, 4);
188 CREATE VIEW v AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2;
192 do_catchsql_test 5.3 {
193 ALTER TABLE t2 RENAME TO one;
194 } {1 {error in view v after rename: ambiguous column name: one.a}}
196 do_execsql_test 5.4 {
200 do_execsql_test 5.5 {
202 CREATE VIEW temp.vv AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2;
206 do_catchsql_test 5.6 {
207 ALTER TABLE t2 RENAME TO one;
208 } {1 {error in view vv after rename: ambiguous column name: one.a}}
210 #-------------------------------------------------------------------------
213 register_tcl_module db
214 proc tcl_command {method args} {
217 return "CREATE TABLE t1(a, b, c)"
223 do_execsql_test 6.0 {
224 CREATE VIRTUAL TABLE x1 USING tcl(tcl_command);
227 do_execsql_test 6.1 {
228 ALTER TABLE x1 RENAME TO x2;
229 SELECT sql FROM sqlite_master WHERE name = 'x2'
230 } {{CREATE VIRTUAL TABLE "x2" USING tcl(tcl_command)}}
232 do_execsql_test 7.1 {
233 CREATE TABLE ddd(db, sql, zOld, zNew, bTemp);
234 INSERT INTO ddd VALUES(
235 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', 'ddd', NULL, 0
237 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0
239 'main', NULL, 'ddd', 'eee', 0
243 sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
244 do_execsql_test 7.2 {
246 sqlite_rename_table(db, 0, 0, sql, zOld, zNew, bTemp)
249 sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
252 #-------------------------------------------------------------------------
256 do_execsql_test 8.1 {
257 ATTACH 'test.db2' AS aux;
258 PRAGMA foreign_keys = on;
259 CREATE TABLE aux.p1(a INTEGER PRIMARY KEY, b);
260 CREATE TABLE aux.c1(x INTEGER PRIMARY KEY, y REFERENCES p1(a));
261 INSERT INTO aux.p1 VALUES(1, 1);
262 INSERT INTO aux.p1 VALUES(2, 2);
263 INSERT INTO aux.c1 VALUES(NULL, 2);
264 CREATE TABLE aux.c2(x INTEGER PRIMARY KEY, y REFERENCES c1(a));
267 do_execsql_test 8.2 {
268 ALTER TABLE aux.p1 RENAME TO ppp;
271 do_execsql_test 8.2 {
272 INSERT INTO aux.c1 VALUES(NULL, 1);
273 SELECT sql FROM aux.sqlite_master WHERE name = 'c1';
274 } {{CREATE TABLE c1(x INTEGER PRIMARY KEY, y REFERENCES "ppp"(a))}}
277 do_execsql_test 9.0 {
278 CREATE TABLE t1(a, b, c);
279 CREATE VIEW v1 AS SELECT * FROM t2;
281 do_catchsql_test 9.1 {
282 ALTER TABLE t1 RENAME TO t3;
283 } {1 {error in view v1: no such table: main.t2}}
284 do_execsql_test 9.2 {
286 CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN
287 INSERT INTO t2 VALUES(new.a);
290 do_catchsql_test 9.3 {
291 ALTER TABLE t1 RENAME TO t3;
292 } {1 {error in trigger tr: no such table: main.t2}}
295 do_execsql_test 9.4 {
298 ATTACH 'test.db2' AS aux;
299 CREATE TRIGGER tr AFTER INSERT ON t1 WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END;
301 CREATE TABLE aux.t1(x);
302 CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END;
304 do_execsql_test 9.5 {
305 ALTER TABLE main.t1 RENAME TO t3;
307 do_execsql_test 9.6 {
308 SELECT sql FROM sqlite_temp_master;
309 SELECT sql FROM sqlite_master WHERE type='trigger';
311 {CREATE TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END}
312 {CREATE TRIGGER tr AFTER INSERT ON "t3" WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END}
315 #-------------------------------------------------------------------------
318 do_execsql_test 10.0 {
319 CREATE VIRTUAL TABLE fff USING fts5(x, y, z);
322 do_execsql_test 10.1 {
324 INSERT INTO fff VALUES('a', 'b', 'c');
325 ALTER TABLE fff RENAME TO ggg;
329 do_execsql_test 10.2 {
334 #-------------------------------------------------------------------------
337 db func trigger trigger
339 proc trigger {args} {
340 lappend ::trigger $args
342 do_execsql_test 11.0 {
343 ATTACH 'test.db2' AS aux;
344 CREATE TABLE aux.t1(a, b, c);
345 CREATE TABLE main.t1(a, b, c);
346 CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN
347 SELECT trigger(new.a, new.b, new.c);
351 do_execsql_test 11.1 {
352 INSERT INTO main.t1 VALUES(1, 2, 3);
353 INSERT INTO aux.t1 VALUES(4, 5, 6);
355 do_test 11.2 { set ::trigger } {{4 5 6}}
357 do_execsql_test 11.3 {
358 SELECT name, tbl_name FROM sqlite_temp_master;
361 do_execsql_test 11.4 {
362 ALTER TABLE main.t1 RENAME TO t2;
363 SELECT name, tbl_name FROM sqlite_temp_master;
366 do_execsql_test 11.5 {
367 ALTER TABLE aux.t1 RENAME TO t2;
368 SELECT name, tbl_name FROM sqlite_temp_master;
371 do_execsql_test 11.6 {
372 INSERT INTO aux.t2 VALUES(7, 8, 9);
374 do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}}
376 #-------------------------------------------------------------------------
378 do_execsql_test 12.0 {
381 CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN
382 INSERT INTO t1(a) VALUES(new.w);
384 CREATE TEMP TABLE t2(x);
387 do_execsql_test 12.1 {
388 ALTER TABLE main.t2 RENAME TO t3;
391 do_execsql_test 12.2 {
392 INSERT INTO t3 VALUES('WWW');
397 #-------------------------------------------------------------------------
399 do_execsql_test 13.0 {
400 CREATE TABLE t1(x, y);
401 CREATE TABLE t2(a, b);
403 CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
404 INSERT INTO log SELECT y FROM t1, t2;
408 do_execsql_test 13.1 {
409 INSERT INTO t1 VALUES(1, 2);
412 do_catchsql_test 13.2 {
413 ALTER TABLE t2 RENAME b TO y;
414 } {1 {error in trigger tr1 after rename: ambiguous column name: y}}
416 #-------------------------------------------------------------------------
420 do_execsql_test 14.0 {
421 CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy);
423 CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB);
425 CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable"
426 WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN
427 DELETE FROM rt WHERE id = OLD."fid";
430 INSERT INTO mytable VALUES(1, X'abcd');
433 do_execsql_test 14.1 {
434 UPDATE mytable SET geom = X'1234'
437 do_execsql_test 14.2 {
438 ALTER TABLE mytable RENAME TO mytable_renamed;
441 do_execsql_test 14.3 {
442 CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN
443 DELETE FROM rt WHERE id=(SELECT min(id) FROM rt);
447 do_execsql_test 14.4 {
448 ALTER TABLE mytable_renamed RENAME TO mytable2;
453 do_execsql_test 14.5 {
454 CREATE TABLE t1(a, b, c);
455 CREATE VIEW v1 AS SELECT * FROM t1;
456 CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN
460 do_execsql_test 14.6 {
461 ALTER TABLE t1 RENAME TO tt1;
464 #-------------------------------------------------------------------------
466 do_execsql_test 15.0 {
467 CREATE TABLE t1(a integer NOT NULL PRIMARY KEY);
468 CREATE VIEW v1 AS SELECT a FROM t1;
469 CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN
470 UPDATE t1 SET a = NEW.a;
472 CREATE TRIGGER tr2 INSTEAD OF INSERT ON v1 BEGIN
478 do_execsql_test 15.1 {
479 INSERT INTO v1 VALUES(1);
480 ALTER TABLE t2 RENAME TO t3;
483 do_execsql_test 15.2 {
484 CREATE TABLE x(f1 integer NOT NULL);
485 CREATE VIEW y AS SELECT f1 AS f1 FROM x;
486 CREATE TRIGGER t INSTEAD OF UPDATE OF f1 ON y BEGIN
487 UPDATE x SET f1 = NEW.f1;
489 CREATE TABLE z (f1 integer NOT NULL PRIMARY KEY);
490 ALTER TABLE z RENAME TO z2;
493 do_execsql_test 15.3 {
494 INSERT INTO x VALUES(1), (2), (3);
495 ALTER TABLE x RENAME f1 TO f2;
499 do_execsql_test 15.4 {
500 UPDATE y SET f1 = 'x' WHERE f1 = 1;
504 do_execsql_test 15.5 {
505 SELECT sql FROM sqlite_master WHERE name = 'y';
506 } {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}
508 #-------------------------------------------------------------------------
509 # Test that it is not possible to rename a shadow table in DEFENSIVE mode.
512 proc vtab_command {method args} {
515 if {[info exists ::vtab_connect_sql]} {
516 execsql $::vtab_connect_sql
518 return "CREATE TABLE t1(a, b, c)"
522 set clist [lindex $args 0]
523 if {[llength $clist]!=1} { error "unexpected constraint list" }
524 catch { array unset C }
525 array set C [lindex $clist 0]
527 return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!"
529 return "cost 1000000 rows 0 idxnum 0 idxstr scan..."
537 register_tcl_module db
539 sqlite3_db_config db DEFENSIVE 1
541 do_execsql_test 16.0 {
542 CREATE VIRTUAL TABLE y1 USING fts3;
546 do_catchsql_test 16.10 {
547 INSERT INTO y1_segments VALUES(1, X'1234567890');
548 } {1 {table y1_segments may not be modified}}
550 do_catchsql_test 16.20 {
551 DROP TABLE y1_segments;
552 } {1 {table y1_segments may not be dropped}}
554 do_catchsql_test 16.20 {
555 ALTER TABLE y1_segments RENAME TO abc;
556 } {1 {table y1_segments may not be altered}}
557 sqlite3_db_config db DEFENSIVE 0
558 do_catchsql_test 16.22 {
559 ALTER TABLE y1_segments RENAME TO abc;
561 sqlite3_db_config db DEFENSIVE 1
562 do_catchsql_test 16.23 {
563 CREATE TABLE y1_segments AS SELECT * FROM abc;
564 } {1 {object name reserved for internal use: y1_segments}}
565 do_catchsql_test 16.24 {
566 CREATE VIEW y1_segments AS SELECT * FROM abc;
567 } {1 {object name reserved for internal use: y1_segments}}
568 sqlite3_db_config db DEFENSIVE 0
569 do_catchsql_test 16.25 {
570 ALTER TABLE abc RENAME TO y1_segments;
572 sqlite3_db_config db DEFENSIVE 1
574 do_execsql_test 16.30 {
575 ALTER TABLE y1 RENAME TO z1;
578 do_execsql_test 16.40 {
579 SELECT * FROM z1_segments;
583 #-------------------------------------------------------------------------
585 do_execsql_test 17.0 {
586 CREATE TABLE sqlite1234 (id integer);
587 ALTER TABLE sqlite1234 RENAME TO User;
588 SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL;
590 User {CREATE TABLE "User" (id integer)}
593 #-------------------------------------------------------------------------
595 do_execsql_test 18.1.0 {
596 CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID;
598 do_execsql_test 18.1.1 {
599 ALTER TABLE t0 RENAME COLUMN c0 TO c1;
601 do_execsql_test 18.1.2 {
602 SELECT sql FROM sqlite_master;
603 } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}}
606 do_execsql_test 18.2.0 {
607 CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0));
609 do_execsql_test 18.2.1 {
610 ALTER TABLE t0 RENAME COLUMN c0 TO c1;
612 do_execsql_test 18.2.2 {
613 SELECT sql FROM sqlite_master;
614 } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}}
616 # 2020-02-23 ticket f50af3e8a565776b
618 do_execsql_test 19.100 {
620 CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1);
621 ALTER TABLE t1 RENAME TO t3;
622 SELECT sql FROM sqlite_master;
623 } {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}}
624 do_execsql_test 19.110 {
625 INSERT INTO t3(x) VALUES(123);
628 do_execsql_test 19.120 {
629 INSERT INTO t3(x) VALUES('xyz');
633 # Ticket 4722bdab08cb14
635 do_execsql_test 20.0 {
637 CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN();
639 do_execsql_test 20.1 {
640 ALTER TABLE a RENAME a TO e;
644 do_execsql_test 21.0 {
647 SELECT NULL INTERSECT
649 likelihood(NULL, (d, (SELECT c)));
651 do_catchsql_test 21.1 {
652 SELECT likelihood(NULL, (d, (SELECT c)));
653 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
654 do_catchsql_test 21.2 {
656 } {1 {1st ORDER BY term does not match any column in the result set}}
658 do_catchsql_test 21.3 {
659 ALTER TABLE a RENAME TO e;
660 } {1 {error in view c: 1st ORDER BY term does not match any column in the result set}}
662 # After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa
663 # Ensure that PRAGMA schema_version=N causes a full schema reload.
666 do_execsql_test 22.0 {
667 CREATE TABLE t1(a INT, b TEXT NOT NULL);
668 INSERT INTO t1 VALUES(1,2),('a','b');
670 PRAGMA writable_schema=ON;
671 UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1';
672 PRAGMA schema_version=1234;
674 PRAGMA integrity_check;
676 do_execsql_test 22.1 {
677 ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78;
681 #-------------------------------------------------------------------------
683 db collate compare64 compare64
685 do_execsql_test 23.1 {
686 CREATE TABLE gigo(a text);
687 CREATE TABLE idx(x text COLLATE compare64);
688 CREATE VIEW v1 AS SELECT * FROM idx WHERE x='abc';
693 do_execsql_test 23.2 {
694 alter table gigo rename to ggiiggoo;
695 alter table idx rename to idx2;
698 do_execsql_test 23.3 {
699 SELECT sql FROM sqlite_master;
701 {CREATE TABLE "ggiiggoo"(a text)}
702 {CREATE TABLE "idx2"(x text COLLATE compare64)}
703 {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE x='abc'}
706 do_execsql_test 23.4 {
707 ALTER TABLE idx2 RENAME x TO y;
708 SELECT sql FROM sqlite_master;
710 {CREATE TABLE "ggiiggoo"(a text)}
711 {CREATE TABLE "idx2"(y text COLLATE compare64)}
712 {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE y='abc'}
715 #-------------------------------------------------------------------------
718 do_execsql_test 24.1.0 {
719 CREATE TABLE t1(a, b);
720 CREATE TRIGGER AFTER INSERT ON t1 BEGIN
721 INSERT INTO nosuchtable VALUES(new.a) ON CONFLICT(a) DO NOTHING;
724 do_catchsql_test 24.1.1 {
725 ALTER TABLE t1 RENAME TO t2;
726 } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
729 do_execsql_test 24.2.0 {
730 CREATE TABLE t1(a, b);
731 CREATE TRIGGER AFTER INSERT ON t1 BEGIN
732 INSERT INTO v1 VALUES(new.a) ON CONFLICT(a) DO NOTHING;
734 CREATE VIEW v1 AS SELECT * FROM nosuchtable;
736 do_catchsql_test 24.2.1 {
737 ALTER TABLE t1 RENAME TO t2;
738 } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
740 #--------------------------------------------------------------------------
743 do_execsql_test 25.1 {
745 CREATE VIEW v3(b) AS WITH b AS (SELECT b FROM (SELECT * FROM t2)) VALUES(1);
748 ifcapable json1&&vtab {
749 do_catchsql_test 25.2 {
750 ALTER TABLE json_each RENAME TO t4;
751 } {1 {table json_each may not be altered}}
754 # 2021-05-01 dbsqlfuzz bc17a306a09329bba0ecc61547077f6178bcf321
755 # Remove a NEVER() inserted on 2019-12-09 that is reachable after all.
758 do_execsql_test 26.1 {
759 CREATE TABLE t1(k,v);
760 CREATE TABLE t2_a(k,v);
761 CREATE VIEW t2 AS SELECT * FROM t2_a;
762 CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
764 SET (k,v)=((WITH cte1(a) AS (SELECT 1 FROM t2) SELECT t2.k FROM t2, cte1),1);
766 ALTER TABLE t1 RENAME TO t1x;
767 INSERT INTO t2_a VALUES(2,3);
768 INSERT INTO t1x VALUES(98,99);
772 #-------------------------------------------------------------------------
775 do_execsql_test 27.1 {
778 c_muyat INTEGER NOT NULL,
782 create table t2 ( abc );
784 CREATE TRIGGER trig AFTER DELETE ON t_sa
786 DELETE FROM t_sa WHERE (
788 WINDOW oamat7fzf AS ( PARTITION BY t_sa.c_d4u )
793 do_execsql_test 27.2 {
794 alter table t_sa rename column c_muyat to c_dg;
797 #-------------------------------------------------------------------------
799 do_execsql_test 29.1 {
800 CREATE TABLE t1(a, b, c);
801 INSERT INTO t1 VALUES('a', 'b', 'c');
804 WITH p AS ( SELECT 1 FROM t1 ),
805 g AS ( SELECT 1 FROM p, t1 )
809 do_execsql_test 29.2 {
813 do_execsql_test 29.2 {
814 ALTER TABLE t1 RENAME TO t2
817 do_execsql_test 29.3 {
818 SELECT sql FROM sqlite_schema WHERE name='v0'
819 } {{CREATE VIEW v0 AS
820 WITH p AS ( SELECT 1 FROM "t2" ),
821 g AS ( SELECT 1 FROM p, "t2" )
824 do_execsql_test 29.4 {
826 WITH p AS ( SELECT 1 FROM t2 ),
827 g AS ( SELECT 1 FROM (
828 WITH i AS (SELECT 1 FROM p, t2)
835 do_execsql_test 29.4 {
839 do_execsql_test 29.5 {
840 ALTER TABLE t2 RENAME TO t3;
843 do_execsql_test 29.5 {
844 SELECT sql FROM sqlite_schema WHERE name='v2'
845 } {{CREATE VIEW v2 AS
846 WITH p AS ( SELECT 1 FROM "t3" ),
847 g AS ( SELECT 1 FROM (
848 WITH i AS (SELECT 1 FROM p, "t3")
855 #-------------------------------------------------------------------------
857 do_execsql_test 28.1 {
859 CREATE TABLE t2(b,c);
860 CREATE TABLE t4(b,c);
861 INSERT INTO t2 VALUES(1,2),(1,3),(2,5);
862 INSERT INTO t4 VALUES(1,2),(1,3),(2,5);
865 WITH RECURSIVE t3(x,y,z) AS (
866 SELECT b,c,NULL FROM t4
868 SELECT x,y,NULL FROM t3, t2
870 SELECT * FROM t3 AS xyz;
873 do_execsql_test 28.2 {
879 do_execsql_test 28.3 {
880 ALTER TABLE t1 RENAME a TO a2; -- fails in v3
883 do_execsql_test 28.4 {
884 ALTER TABLE t2 RENAME TO t5;
887 do_execsql_test 28.5 {
888 SELECT sql FROM sqlite_schema WHERE name='v3'
889 } {{CREATE VIEW v3 AS
890 WITH RECURSIVE t3(x,y,z) AS (
891 SELECT b,c,NULL FROM t4
893 SELECT x,y,NULL FROM t3, "t5"
895 SELECT * FROM t3 AS xyz}}
897 #-------------------------------------------------------------------------
899 do_execsql_test 30.0 {
900 CREATE TABLE t1(a,b,c,d,e,f);
901 CREATE TABLE t2(a,b,c);
902 CREATE INDEX t1abc ON t1(a,b,c+d+e);
903 CREATE VIEW v1(x,y) AS
904 SELECT t1.b,t2.b FROM t1,t2 WHERE t1.a=t2.a
905 GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10;
906 CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN 'no' NOT NULL BEGIN
907 INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
911 SELECT current_time+x FROM c1 WHERE x
913 SELECT 1+x FROM c1 WHERE x<1
914 ), c2(x) AS (VALUES(0),(1))
915 SELECT * FROM c1 AS x1, c2 AS x2, (
916 SELECT x+1 FROM c1 WHERE x IS NOT TRUE
918 SELECT 1+x FROM c1 WHERE 1<x
923 do_execsql_test 30.1 {
924 ALTER TABLE t1 RENAME TO t1x;
927 do_execsql_test 30.2 {
928 SELECT sql FROM sqlite_schema ORDER BY rowid
930 {CREATE TABLE "t1x"(a,b,c,d,e,f)}
931 {CREATE TABLE t2(a,b,c)}
932 {CREATE INDEX t1abc ON "t1x"(a,b,c+d+e)}
933 {CREATE VIEW v1(x,y) AS
934 SELECT "t1x".b,t2.b FROM "t1x",t2 WHERE "t1x".a=t2.a
935 GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10}
936 {CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN 'no' NOT NULL BEGIN
937 INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
941 SELECT current_time+x FROM c1 WHERE x
943 SELECT 1+x FROM c1 WHERE x<1
944 ), c2(x) AS (VALUES(0),(1))
945 SELECT * FROM c1 AS x1, c2 AS x2, (
946 SELECT x+1 FROM c1 WHERE x IS NOT TRUE
948 SELECT 1+x FROM c1 WHERE 1<x
953 #-------------------------------------------------------------------------
955 do_execsql_test 31.0 {
957 CREATE VIEW vvv AS WITH x AS (WITH y AS (SELECT * FROM x) SELECT 1) SELECT 1;
960 do_execsql_test 31.1 {
964 do_execsql_test 31.2 {
965 ALTER TABLE t1 RENAME TO t1x;
968 do_execsql_test 31.3 {
969 ALTER TABLE t1x RENAME q TO x;
972 # 2021-07-02 OSSFuzz https://oss-fuzz.com/testcase-detail/5517690440646656
973 # Bad assert() statement
976 do_catchsql_test 32.0 {
978 CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN
979 UPDATE t1 SET x=x FROM (SELECT*);
981 ALTER TABLE t1 RENAME TO x;
982 } {1 {error in trigger r1: no tables specified}}
984 # 2023-04-13 https://sqlite.org/forum/forumpost/ff3840145a
987 do_execsql_test 33.0 {
988 CREATE TABLE t1(a TEXT);
989 INSERT INTO t1(a) VALUES('abc'),('def'),(NULL);
990 CREATE TABLE t2(b TEXT);
991 CREATE TRIGGER r3 AFTER INSERT ON t1 BEGIN
992 UPDATE t2 SET (b,a)=(SELECT 1) FROM t1 JOIN t2 ON (SELECT * FROM (SELECT a));
995 do_catchsql_test 33.1 {
996 ALTER TABLE t1 RENAME COLUMN a TO b;
997 } {1 {error in trigger r3 after rename: no such column: a}}
998 do_execsql_test 33.2 {
999 SELECT quote(a) FROM t1 ORDER BY +a;
1000 } {NULL 'abc' 'def'}