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;
545 do_catchsql_test 16.10 {
546 INSERT INTO y1_segments VALUES(1, X'1234567890');
547 } {1 {table y1_segments may not be modified}}
549 do_catchsql_test 16.20 {
550 DROP TABLE y1_segments;
551 } {1 {table y1_segments may not be dropped}}
553 do_catchsql_test 16.20 {
554 ALTER TABLE y1_segments RENAME TO abc;
555 } {1 {table y1_segments may not be altered}}
556 sqlite3_db_config db DEFENSIVE 0
557 do_catchsql_test 16.22 {
558 ALTER TABLE y1_segments RENAME TO abc;
560 sqlite3_db_config db DEFENSIVE 1
561 do_catchsql_test 16.23 {
562 CREATE TABLE y1_segments AS SELECT * FROM abc;
563 } {1 {object name reserved for internal use: y1_segments}}
564 do_catchsql_test 16.24 {
565 CREATE VIEW y1_segments AS SELECT * FROM abc;
566 } {1 {object name reserved for internal use: y1_segments}}
567 sqlite3_db_config db DEFENSIVE 0
568 do_catchsql_test 16.25 {
569 ALTER TABLE abc RENAME TO y1_segments;
571 sqlite3_db_config db DEFENSIVE 1
573 do_execsql_test 16.30 {
574 ALTER TABLE y1 RENAME TO z1;
577 do_execsql_test 16.40 {
578 SELECT * FROM z1_segments;
582 #-------------------------------------------------------------------------
584 do_execsql_test 17.0 {
585 CREATE TABLE sqlite1234 (id integer);
586 ALTER TABLE sqlite1234 RENAME TO User;
587 SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL;
589 User {CREATE TABLE "User" (id integer)}
592 #-------------------------------------------------------------------------
594 do_execsql_test 18.1.0 {
595 CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID;
597 do_execsql_test 18.1.1 {
598 ALTER TABLE t0 RENAME COLUMN c0 TO c1;
600 do_execsql_test 18.1.2 {
601 SELECT sql FROM sqlite_master;
602 } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}}
605 do_execsql_test 18.2.0 {
606 CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0));
608 do_execsql_test 18.2.1 {
609 ALTER TABLE t0 RENAME COLUMN c0 TO c1;
611 do_execsql_test 18.2.2 {
612 SELECT sql FROM sqlite_master;
613 } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}}
615 # 2020-02-23 ticket f50af3e8a565776b
617 do_execsql_test 19.100 {
619 CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1);
620 ALTER TABLE t1 RENAME TO t3;
621 SELECT sql FROM sqlite_master;
622 } {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}}
623 do_execsql_test 19.110 {
624 INSERT INTO t3(x) VALUES(123);
627 do_execsql_test 19.120 {
628 INSERT INTO t3(x) VALUES('xyz');
632 # Ticket 4722bdab08cb14
634 do_execsql_test 20.0 {
636 CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN();
638 do_execsql_test 20.1 {
639 ALTER TABLE a RENAME a TO e;
643 do_execsql_test 21.0 {
646 SELECT NULL INTERSECT
648 likelihood(NULL, (d, (SELECT c)));
650 do_catchsql_test 21.1 {
651 SELECT likelihood(NULL, (d, (SELECT c)));
652 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
653 do_catchsql_test 21.2 {
655 } {1 {1st ORDER BY term does not match any column in the result set}}
657 do_catchsql_test 21.3 {
658 ALTER TABLE a RENAME TO e;
659 } {1 {error in view c: 1st ORDER BY term does not match any column in the result set}}
661 # After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa
662 # Ensure that PRAGMA schema_version=N causes a full schema reload.
665 do_execsql_test 22.0 {
666 CREATE TABLE t1(a INT, b TEXT NOT NULL);
667 INSERT INTO t1 VALUES(1,2),('a','b');
669 PRAGMA writable_schema=ON;
670 UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1';
671 PRAGMA schema_version=1234;
673 PRAGMA integrity_check;
675 do_execsql_test 22.1 {
676 ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78;
680 #-------------------------------------------------------------------------
682 db collate compare64 compare64
684 do_execsql_test 23.1 {
685 CREATE TABLE gigo(a text);
686 CREATE TABLE idx(x text COLLATE compare64);
687 CREATE VIEW v1 AS SELECT * FROM idx WHERE x='abc';
692 do_execsql_test 23.2 {
693 alter table gigo rename to ggiiggoo;
694 alter table idx rename to idx2;
697 do_execsql_test 23.3 {
698 SELECT sql FROM sqlite_master;
700 {CREATE TABLE "ggiiggoo"(a text)}
701 {CREATE TABLE "idx2"(x text COLLATE compare64)}
702 {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE x='abc'}
705 do_execsql_test 23.4 {
706 ALTER TABLE idx2 RENAME x TO y;
707 SELECT sql FROM sqlite_master;
709 {CREATE TABLE "ggiiggoo"(a text)}
710 {CREATE TABLE "idx2"(y text COLLATE compare64)}
711 {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE y='abc'}
714 #-------------------------------------------------------------------------
717 do_execsql_test 24.1.0 {
718 CREATE TABLE t1(a, b);
719 CREATE TRIGGER AFTER INSERT ON t1 BEGIN
720 INSERT INTO nosuchtable VALUES(new.a) ON CONFLICT(a) DO NOTHING;
723 do_catchsql_test 24.1.1 {
724 ALTER TABLE t1 RENAME TO t2;
725 } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
728 do_execsql_test 24.2.0 {
729 CREATE TABLE t1(a, b);
730 CREATE TRIGGER AFTER INSERT ON t1 BEGIN
731 INSERT INTO v1 VALUES(new.a) ON CONFLICT(a) DO NOTHING;
733 CREATE VIEW v1 AS SELECT * FROM nosuchtable;
735 do_catchsql_test 24.2.1 {
736 ALTER TABLE t1 RENAME TO t2;
737 } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
739 #--------------------------------------------------------------------------
742 do_execsql_test 25.1 {
744 CREATE VIEW v3(b) AS WITH b AS (SELECT b FROM (SELECT * FROM t2)) VALUES(1);
747 ifcapable json1&&vtab {
748 do_catchsql_test 25.2 {
749 ALTER TABLE json_each RENAME TO t4;
750 } {1 {table json_each may not be altered}}
753 # 2021-05-01 dbsqlfuzz bc17a306a09329bba0ecc61547077f6178bcf321
754 # Remove a NEVER() inserted on 2019-12-09 that is reachable after all.
757 do_execsql_test 26.1 {
758 CREATE TABLE t1(k,v);
759 CREATE TABLE t2_a(k,v);
760 CREATE VIEW t2 AS SELECT * FROM t2_a;
761 CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
763 SET (k,v)=((WITH cte1(a) AS (SELECT 1 FROM t2) SELECT t2.k FROM t2, cte1),1);
765 ALTER TABLE t1 RENAME TO t1x;
766 INSERT INTO t2_a VALUES(2,3);
767 INSERT INTO t1x VALUES(98,99);
771 #-------------------------------------------------------------------------
774 do_execsql_test 27.1 {
777 c_muyat INTEGER NOT NULL,
781 create table t2 ( abc );
783 CREATE TRIGGER trig AFTER DELETE ON t_sa
785 DELETE FROM t_sa WHERE (
787 WINDOW oamat7fzf AS ( PARTITION BY t_sa.c_d4u )
792 do_execsql_test 27.2 {
793 alter table t_sa rename column c_muyat to c_dg;
796 #-------------------------------------------------------------------------
798 do_execsql_test 29.1 {
799 CREATE TABLE t1(a, b, c);
800 INSERT INTO t1 VALUES('a', 'b', 'c');
803 WITH p AS ( SELECT 1 FROM t1 ),
804 g AS ( SELECT 1 FROM p, t1 )
808 do_execsql_test 29.2 {
812 do_execsql_test 29.2 {
813 ALTER TABLE t1 RENAME TO t2
816 do_execsql_test 29.3 {
817 SELECT sql FROM sqlite_schema WHERE name='v0'
818 } {{CREATE VIEW v0 AS
819 WITH p AS ( SELECT 1 FROM "t2" ),
820 g AS ( SELECT 1 FROM p, "t2" )
823 do_execsql_test 29.4 {
825 WITH p AS ( SELECT 1 FROM t2 ),
826 g AS ( SELECT 1 FROM (
827 WITH i AS (SELECT 1 FROM p, t2)
834 do_execsql_test 29.4 {
838 do_execsql_test 29.5 {
839 ALTER TABLE t2 RENAME TO t3;
842 do_execsql_test 29.5 {
843 SELECT sql FROM sqlite_schema WHERE name='v2'
844 } {{CREATE VIEW v2 AS
845 WITH p AS ( SELECT 1 FROM "t3" ),
846 g AS ( SELECT 1 FROM (
847 WITH i AS (SELECT 1 FROM p, "t3")
854 #-------------------------------------------------------------------------
856 do_execsql_test 28.1 {
858 CREATE TABLE t2(b,c);
859 CREATE TABLE t4(b,c);
860 INSERT INTO t2 VALUES(1,2),(1,3),(2,5);
861 INSERT INTO t4 VALUES(1,2),(1,3),(2,5);
864 WITH RECURSIVE t3(x,y,z) AS (
865 SELECT b,c,NULL FROM t4
867 SELECT x,y,NULL FROM t3, t2
869 SELECT * FROM t3 AS xyz;
872 do_execsql_test 28.2 {
878 do_execsql_test 28.3 {
879 ALTER TABLE t1 RENAME a TO a2; -- fails in v3
882 do_execsql_test 28.4 {
883 ALTER TABLE t2 RENAME TO t5;
886 do_execsql_test 28.5 {
887 SELECT sql FROM sqlite_schema WHERE name='v3'
888 } {{CREATE VIEW v3 AS
889 WITH RECURSIVE t3(x,y,z) AS (
890 SELECT b,c,NULL FROM t4
892 SELECT x,y,NULL FROM t3, "t5"
894 SELECT * FROM t3 AS xyz}}
896 #-------------------------------------------------------------------------
898 do_execsql_test 30.0 {
899 CREATE TABLE t1(a,b,c,d,e,f);
900 CREATE TABLE t2(a,b,c);
901 CREATE INDEX t1abc ON t1(a,b,c+d+e);
902 CREATE VIEW v1(x,y) AS
903 SELECT t1.b,t2.b FROM t1,t2 WHERE t1.a=t2.a
904 GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10;
905 CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN 'no' NOT NULL BEGIN
906 INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
910 SELECT current_time+x FROM c1 WHERE x
912 SELECT 1+x FROM c1 WHERE x<1
913 ), c2(x) AS (VALUES(0),(1))
914 SELECT * FROM c1 AS x1, c2 AS x2, (
915 SELECT x+1 FROM c1 WHERE x IS NOT TRUE
917 SELECT 1+x FROM c1 WHERE 1<x
922 do_execsql_test 30.1 {
923 ALTER TABLE t1 RENAME TO t1x;
926 do_execsql_test 30.2 {
927 SELECT sql FROM sqlite_schema ORDER BY rowid
929 {CREATE TABLE "t1x"(a,b,c,d,e,f)}
930 {CREATE TABLE t2(a,b,c)}
931 {CREATE INDEX t1abc ON "t1x"(a,b,c+d+e)}
932 {CREATE VIEW v1(x,y) AS
933 SELECT "t1x".b,t2.b FROM "t1x",t2 WHERE "t1x".a=t2.a
934 GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10}
935 {CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN 'no' NOT NULL BEGIN
936 INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
940 SELECT current_time+x FROM c1 WHERE x
942 SELECT 1+x FROM c1 WHERE x<1
943 ), c2(x) AS (VALUES(0),(1))
944 SELECT * FROM c1 AS x1, c2 AS x2, (
945 SELECT x+1 FROM c1 WHERE x IS NOT TRUE
947 SELECT 1+x FROM c1 WHERE 1<x
952 #-------------------------------------------------------------------------
954 do_execsql_test 31.0 {
956 CREATE VIEW vvv AS WITH x AS (WITH y AS (SELECT * FROM x) SELECT 1) SELECT 1;
959 do_execsql_test 31.1 {
963 do_execsql_test 31.2 {
964 ALTER TABLE t1 RENAME TO t1x;
967 do_execsql_test 31.3 {
968 ALTER TABLE t1x RENAME q TO x;