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 regression tests for SQLite library. The
12 # focus of this script is testing the AUTOINCREMENT features.
14 # $Id: autoinc.test,v 1.14 2009/06/23 20:28:54 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix autoinc
21 # If the library is not compiled with autoincrement support then
22 # skip all tests in this file.
24 ifcapable {!autoinc} {
29 if {[permutation]=="inmemory_journal"} {
34 sqlite3_db_config_lookaside db 0 0 0
36 # The database is initially empty.
40 SELECT name FROM sqlite_master WHERE type='table';
44 # Add a table with the AUTOINCREMENT feature. Verify that the
45 # SQLITE_SEQUENCE table gets created.
49 CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
50 SELECT name FROM sqlite_master WHERE type='table';
52 } {t1 sqlite_sequence}
54 # The SQLITE_SEQUENCE table is initially empty
58 SELECT * FROM sqlite_sequence;
61 do_test autoinc-1.3.1 {
63 CREATE INDEX seqidx ON sqlite_sequence(name)
65 } {1 {table sqlite_sequence may not be indexed}}
67 # Close and reopen the database. Verify that everything is still there.
73 SELECT * FROM sqlite_sequence;
77 # We are not allowed to drop the sqlite_sequence table.
80 catchsql {DROP TABLE sqlite_sequence}
81 } {1 {table sqlite_sequence may not be dropped}}
83 execsql {SELECT name FROM sqlite_master WHERE type='table'}
84 } {t1 sqlite_sequence}
86 # Insert an entries into the t1 table and make sure the largest key
87 # is always recorded in the sqlite_sequence table.
91 SELECT * FROM sqlite_sequence
96 INSERT INTO t1 VALUES(12,34);
97 SELECT * FROM sqlite_sequence;
100 do_test autoinc-2.3 {
102 INSERT INTO t1 VALUES(1,23);
103 SELECT * FROM sqlite_sequence;
106 do_test autoinc-2.4 {
108 INSERT INTO t1 VALUES(123,456);
109 SELECT * FROM sqlite_sequence;
112 do_test autoinc-2.5 {
114 INSERT INTO t1 VALUES(NULL,567);
115 SELECT * FROM sqlite_sequence;
118 do_test autoinc-2.6 {
120 DELETE FROM t1 WHERE y=567;
121 SELECT * FROM sqlite_sequence;
124 do_test autoinc-2.7 {
126 INSERT INTO t1 VALUES(NULL,567);
127 SELECT * FROM sqlite_sequence;
130 do_test autoinc-2.8 {
133 SELECT * FROM sqlite_sequence;
136 do_test autoinc-2.9 {
138 INSERT INTO t1 VALUES(12,34);
139 SELECT * FROM sqlite_sequence;
142 do_test autoinc-2.10 {
144 INSERT INTO t1 VALUES(125,456);
145 SELECT * FROM sqlite_sequence;
148 do_test autoinc-2.11 {
150 INSERT INTO t1 VALUES(-1234567,-1);
151 SELECT * FROM sqlite_sequence;
154 do_test autoinc-2.12 {
156 INSERT INTO t1 VALUES(234,5678);
157 SELECT * FROM sqlite_sequence;
160 do_test autoinc-2.13 {
163 INSERT INTO t1 VALUES(NULL,1);
164 SELECT * FROM sqlite_sequence;
167 do_test autoinc-2.14 {
173 # Manually change the autoincrement values in sqlite_sequence.
175 do_test autoinc-2.20 {
177 UPDATE sqlite_sequence SET seq=1234 WHERE name='t1';
178 INSERT INTO t1 VALUES(NULL,2);
182 do_test autoinc-2.21 {
184 SELECT * FROM sqlite_sequence;
187 do_test autoinc-2.22 {
189 UPDATE sqlite_sequence SET seq=NULL WHERE name='t1';
190 INSERT INTO t1 VALUES(NULL,3);
193 } {235 1 1235 2 1236 3}
194 do_test autoinc-2.23 {
196 SELECT * FROM sqlite_sequence;
199 do_test autoinc-2.24 {
201 UPDATE sqlite_sequence SET seq='a-string' WHERE name='t1';
202 INSERT INTO t1 VALUES(NULL,4);
205 } {235 1 1235 2 1236 3 1237 4}
206 do_test autoinc-2.25 {
208 SELECT * FROM sqlite_sequence;
211 do_test autoinc-2.26 {
213 DELETE FROM sqlite_sequence WHERE name='t1';
214 INSERT INTO t1 VALUES(NULL,5);
217 } {235 1 1235 2 1236 3 1237 4 1238 5}
218 do_test autoinc-2.27 {
220 SELECT * FROM sqlite_sequence;
223 do_test autoinc-2.28 {
225 UPDATE sqlite_sequence SET seq='-12345678901234567890'
227 INSERT INTO t1 VALUES(NULL,6);
230 } {235 1 1235 2 1236 3 1237 4 1238 5 1239 6}
231 do_test autoinc-2.29 {
233 SELECT * FROM sqlite_sequence;
237 # Test multi-row inserts
239 do_test autoinc-2.50 {
241 DELETE FROM t1 WHERE y>=3;
242 INSERT INTO t1 SELECT NULL, y+2 FROM t1;
245 } {235 1 1235 2 1240 3 1241 4}
246 do_test autoinc-2.51 {
248 SELECT * FROM sqlite_sequence
253 do_test autoinc-2.52 {
255 CREATE TEMP TABLE t2 AS SELECT y FROM t1;
258 INSERT INTO t1 SELECT NULL, y+4 FROM t2;
261 } {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
262 do_test autoinc-2.53 {
264 SELECT * FROM sqlite_sequence
267 do_test autoinc-2.54 {
270 INSERT INTO t1 SELECT NULL, y FROM t2;
273 } {1246 1 1247 2 1248 3 1249 4}
274 do_test autoinc-2.55 {
276 SELECT * FROM sqlite_sequence
281 # Create multiple AUTOINCREMENT tables. Make sure all sequences are
282 # tracked separately and do not interfere with one another.
284 do_test autoinc-2.70 {
289 CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f);
290 INSERT INTO t2(d) VALUES(1);
291 SELECT * FROM sqlite_sequence;
293 } [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}]
294 do_test autoinc-2.71 {
296 INSERT INTO t2(d) VALUES(2);
297 SELECT * FROM sqlite_sequence;
299 } [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}]
300 do_test autoinc-2.72 {
302 INSERT INTO t1(x) VALUES(10000);
303 SELECT * FROM sqlite_sequence;
306 do_test autoinc-2.73 {
308 CREATE TABLE t3(g INTEGER PRIMARY KEY AUTOINCREMENT, h);
309 INSERT INTO t3(h) VALUES(1);
310 SELECT * FROM sqlite_sequence;
312 } {t1 10000 t2 2 t3 1}
313 do_test autoinc-2.74 {
315 INSERT INTO t2(d,e) VALUES(3,100);
316 SELECT * FROM sqlite_sequence;
318 } {t1 10000 t2 100 t3 1}
321 # When a table with an AUTOINCREMENT is deleted, the corresponding entry
322 # in the SQLITE_SEQUENCE table should also be deleted. But the SQLITE_SEQUENCE
323 # table itself should remain behind.
325 do_test autoinc-3.1 {
326 execsql {SELECT name FROM sqlite_sequence}
328 do_test autoinc-3.2 {
331 SELECT name FROM sqlite_sequence;
334 do_test autoinc-3.3 {
337 SELECT name FROM sqlite_sequence;
340 do_test autoinc-3.4 {
343 SELECT name FROM sqlite_sequence;
347 # AUTOINCREMENT on TEMP tables.
350 do_test autoinc-4.1 {
352 SELECT 1, name FROM sqlite_master WHERE type='table';
353 SELECT 2, name FROM temp.sqlite_master WHERE type='table';
355 } {1 sqlite_sequence}
356 do_test autoinc-4.2 {
358 CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
359 CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
360 SELECT 1, name FROM sqlite_master WHERE type='table';
361 SELECT 2, name FROM sqlite_temp_master WHERE type='table';
363 } {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
364 do_test autoinc-4.3 {
366 SELECT 1, * FROM main.sqlite_sequence;
367 SELECT 2, * FROM temp.sqlite_sequence;
370 do_test autoinc-4.4 {
372 INSERT INTO t1 VALUES(10,1);
373 INSERT INTO t3 VALUES(20,2);
374 INSERT INTO t1 VALUES(NULL,3);
375 INSERT INTO t3 VALUES(NULL,4);
380 do_test autoinc-4.4.1 {
382 SELECT * FROM t1 UNION ALL SELECT * FROM t3;
384 } {10 1 11 3 20 2 21 4}
385 } ;# ifcapable compound
387 do_test autoinc-4.5 {
389 SELECT 1, * FROM main.sqlite_sequence;
390 SELECT 2, * FROM temp.sqlite_sequence;
393 do_test autoinc-4.6 {
395 INSERT INTO t1 SELECT * FROM t3;
396 SELECT 1, * FROM main.sqlite_sequence;
397 SELECT 2, * FROM temp.sqlite_sequence;
400 do_test autoinc-4.7 {
402 INSERT INTO t3 SELECT x+100, y FROM t1;
403 SELECT 1, * FROM main.sqlite_sequence;
404 SELECT 2, * FROM temp.sqlite_sequence;
407 do_test autoinc-4.8 {
410 SELECT 1, * FROM main.sqlite_sequence;
411 SELECT 2, * FROM temp.sqlite_sequence;
414 do_test autoinc-4.9 {
416 CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
417 INSERT INTO t2 SELECT * FROM t1;
419 SELECT 1, * FROM main.sqlite_sequence;
420 SELECT 2, * FROM temp.sqlite_sequence;
423 do_test autoinc-4.10 {
426 SELECT 1, * FROM main.sqlite_sequence;
427 SELECT 2, * FROM temp.sqlite_sequence;
432 # Make sure AUTOINCREMENT works on ATTACH-ed tables.
434 ifcapable tempdb&&attach {
435 do_test autoinc-5.1 {
437 forcedelete test2.db-journal
440 CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
441 CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
444 ATTACH 'test2.db' as aux;
445 SELECT 1, * FROM main.sqlite_sequence;
446 SELECT 2, * FROM temp.sqlite_sequence;
447 SELECT 3, * FROM aux.sqlite_sequence;
450 do_test autoinc-5.2 {
452 INSERT INTO t4 VALUES(NULL,1);
453 SELECT 1, * FROM main.sqlite_sequence;
454 SELECT 2, * FROM temp.sqlite_sequence;
455 SELECT 3, * FROM aux.sqlite_sequence;
458 do_test autoinc-5.3 {
460 INSERT INTO t5 VALUES(100,200);
461 SELECT * FROM sqlite_sequence
464 do_test autoinc-5.4 {
466 SELECT 1, * FROM main.sqlite_sequence;
467 SELECT 2, * FROM temp.sqlite_sequence;
468 SELECT 3, * FROM aux.sqlite_sequence;
473 # Requirement REQ00310: Make sure an insert fails if the sequence is
474 # already at its maximum value.
476 ifcapable {rowid32} {
477 do_test autoinc-6.1 {
479 CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
480 INSERT INTO t6 VALUES(2147483647,1);
481 SELECT seq FROM main.sqlite_sequence WHERE name='t6';
485 ifcapable {!rowid32} {
486 do_test autoinc-6.1 {
488 CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
489 INSERT INTO t6 VALUES(9223372036854775807,1);
490 SELECT seq FROM main.sqlite_sequence WHERE name='t6';
492 } 9223372036854775807
494 do_test autoinc-6.2 {
496 INSERT INTO t6 VALUES(NULL,1);
498 } {1 {database or disk is full}}
500 # Allow the AUTOINCREMENT keyword inside the parentheses
501 # on a separate PRIMARY KEY designation.
503 do_test autoinc-7.1 {
505 CREATE TABLE t7(x INTEGER, y REAL, PRIMARY KEY(x AUTOINCREMENT));
506 INSERT INTO t7(y) VALUES(123);
507 INSERT INTO t7(y) VALUES(234);
509 INSERT INTO t7(y) VALUES(345);
514 # Test that if the AUTOINCREMENT is applied to a non integer primary key
515 # the error message is sensible.
516 do_test autoinc-7.2 {
518 CREATE TABLE t8(x TEXT PRIMARY KEY AUTOINCREMENT);
520 } {1 {AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY}}
523 # Ticket #1283. Make sure that preparing but never running a statement
524 # that creates the sqlite_sequence table does not mess up the database.
526 do_test autoinc-8.1 {
531 set DB [sqlite3_connection_pointer db]
532 set STMT [sqlite3_prepare $DB {
534 x INTEGER PRIMARY KEY AUTOINCREMENT
537 sqlite3_finalize $STMT
538 set STMT [sqlite3_prepare $DB {
540 x INTEGER PRIMARY KEY AUTOINCREMENT
544 sqlite3_finalize $STMT
546 INSERT INTO t1 VALUES(NULL);
552 # Make sure the sqlite_sequence table is not damaged when doing
553 # an empty insert - an INSERT INTO ... SELECT ... where the SELECT
554 # clause returns an empty set.
556 do_test autoinc-9.1 {
558 CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
559 INSERT INTO t2 VALUES(NULL, 1);
560 CREATE TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
561 INSERT INTO t3 SELECT * FROM t2 WHERE y>1;
563 SELECT * FROM sqlite_sequence WHERE name='t3';
568 catchsql { pragma recursive_triggers = off }
570 # Ticket #3928. Make sure that triggers to not make extra slots in
571 # the SQLITE_SEQUENCE table.
573 do_test autoinc-3928.1 {
575 CREATE TABLE t3928(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
576 CREATE TRIGGER t3928r1 BEFORE INSERT ON t3928 BEGIN
577 INSERT INTO t3928(b) VALUES('before1');
578 INSERT INTO t3928(b) VALUES('before2');
580 CREATE TRIGGER t3928r2 AFTER INSERT ON t3928 BEGIN
581 INSERT INTO t3928(b) VALUES('after1');
582 INSERT INTO t3928(b) VALUES('after2');
584 INSERT INTO t3928(b) VALUES('test');
585 SELECT * FROM t3928 ORDER BY a;
587 } {1 before1 2 after1 3 after2 4 before2 5 after1 6 after2 7 test 8 before1 9 before2 10 after1 11 before1 12 before2 13 after2}
588 do_test autoinc-3928.2 {
590 SELECT * FROM sqlite_sequence WHERE name='t3928'
594 do_test autoinc-3928.3 {
596 DROP TRIGGER t3928r1;
597 DROP TRIGGER t3928r2;
598 CREATE TRIGGER t3928r3 BEFORE UPDATE ON t3928
599 WHEN typeof(new.b)=='integer' BEGIN
600 INSERT INTO t3928(b) VALUES('before-int-' || new.b);
602 CREATE TRIGGER t3928r4 AFTER UPDATE ON t3928
603 WHEN typeof(new.b)=='integer' BEGIN
604 INSERT INTO t3928(b) VALUES('after-int-' || new.b);
606 DELETE FROM t3928 WHERE a!=1;
607 UPDATE t3928 SET b=456 WHERE a=1;
608 SELECT * FROM t3928 ORDER BY a;
610 } {1 456 14 before-int-456 15 after-int-456}
611 do_test autoinc-3928.4 {
613 SELECT * FROM sqlite_sequence WHERE name='t3928'
617 do_test autoinc-3928.5 {
619 CREATE TABLE t3928b(x);
620 INSERT INTO t3928b VALUES(100);
621 INSERT INTO t3928b VALUES(200);
622 INSERT INTO t3928b VALUES(300);
624 CREATE TABLE t3928c(y INTEGER PRIMARY KEY AUTOINCREMENT, z);
625 CREATE TRIGGER t3928br1 BEFORE DELETE ON t3928b BEGIN
626 INSERT INTO t3928(b) VALUES('before-del-'||old.x);
627 INSERT INTO t3928c(z) VALUES('before-del-'||old.x);
629 CREATE TRIGGER t3928br2 AFTER DELETE ON t3928b BEGIN
630 INSERT INTO t3928(b) VALUES('after-del-'||old.x);
631 INSERT INTO t3928c(z) VALUES('after-del-'||old.x);
634 SELECT * FROM t3928 ORDER BY a;
636 } {16 before-del-100 17 after-del-100 18 before-del-200 19 after-del-200 20 before-del-300 21 after-del-300}
637 do_test autoinc-3928.6 {
639 SELECT * FROM t3928c ORDER BY y;
641 } {1 before-del-100 2 after-del-100 3 before-del-200 4 after-del-200 5 before-del-300 6 after-del-300}
642 do_test autoinc-3928.7 {
644 SELECT * FROM sqlite_sequence WHERE name LIKE 't3928%' ORDER BY name;
646 } {t3928 21 t3928c 6}
648 # Ticket [a696379c1f0886615541a48b35bd8181a80e88f8]
649 do_test autoinc-a69637.1 {
651 CREATE TABLE ta69637_1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
652 CREATE TABLE ta69637_2(z);
653 CREATE TRIGGER ra69637_1 AFTER INSERT ON ta69637_2 BEGIN
654 INSERT INTO ta69637_1(y) VALUES(new.z+1);
656 INSERT INTO ta69637_2 VALUES(123);
657 SELECT * FROM ta69637_1;
660 do_test autoinc-a69637.2 {
662 CREATE VIEW va69637_2 AS SELECT * FROM ta69637_2;
663 CREATE TRIGGER ra69637_2 INSTEAD OF INSERT ON va69637_2 BEGIN
664 INSERT INTO ta69637_1(y) VALUES(new.z+10000);
666 INSERT INTO va69637_2 VALUES(123);
667 SELECT * FROM ta69637_1;
672 # 2016-10-03 ticket https://www.sqlite.org/src/tktview/7b3328086a5c1
673 # Make sure autoincrement plays nicely with the xfer optimization
675 do_execsql_test autoinc-10.1 {
676 DELETE FROM sqlite_sequence;
677 CREATE TABLE t10a(a INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE);
678 INSERT INTO t10a VALUES(888,9999);
679 CREATE TABLE t10b(x INTEGER PRIMARY KEY AUTOINCREMENT, y UNIQUE);
680 INSERT INTO t10b SELECT * FROM t10a;
681 SELECT * FROM sqlite_sequence;
682 } {t10a 888 t10b 888}
684 # 2018-04-21 autoincrement does not cause problems for upsert
686 do_execsql_test autoinc-11.1 {
687 CREATE TABLE t11(a INTEGER PRIMARY KEY AUTOINCREMENT,b UNIQUE);
688 INSERT INTO t11(a,b) VALUES(2,3),(5,6),(4,3),(1,2)
689 ON CONFLICT(b) DO UPDATE SET a=a+1000;
690 SELECT seq FROM sqlite_sequence WHERE name='t11';
693 # 2018-05-23 ticket d8dc2b3a58cd5dc2918a1d4acbba4676a23ada4c
694 # Does not crash if the sqlite_sequence table schema is missing
697 do_test autoinc-12.1 {
701 sqlite3_db_config db DEFENSIVE 0
703 CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
704 PRAGMA writable_schema=on;
705 UPDATE sqlite_master SET
706 sql=replace(sql,'fake_','sqlite_'),
707 name='sqlite_sequence',
708 tbl_name='sqlite_sequence'
709 WHERE name='fake_sequence';
713 set res [catch {db eval {
714 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
715 INSERT INTO t1(b) VALUES('one');
718 } {1 {database disk image is malformed}}
719 do_test autoinc-12.2 {
723 sqlite3_db_config db DEFENSIVE 0
725 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
726 INSERT INTO t1(b) VALUES('one');
727 PRAGMA writable_schema=on;
728 UPDATE sqlite_master SET
729 sql=replace(sql,'sqlite_','x_'),
731 tbl_name='x_sequence'
732 WHERE name='sqlite_sequence';
736 set res [catch {db eval {
737 INSERT INTO t1(b) VALUES('two');
740 } {1 {database disk image is malformed}}
742 set err "database disk image is malformed"
744 set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error}
746 do_test autoinc-12.3 {
750 sqlite3_db_config db DEFENSIVE 0
752 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
753 INSERT INTO t1(b) VALUES('one');
754 PRAGMA writable_schema=on;
755 UPDATE sqlite_master SET
756 sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage'
757 WHERE name='sqlite_sequence';
761 set res [catch {db eval {
762 INSERT INTO t1(b) VALUES('two');
766 do_test autoinc-12.4 {
771 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
772 INSERT INTO t1(b) VALUES('one');
773 CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
775 set root1 [db one {SELECT rootpage FROM sqlite_master
776 WHERE name='sqlite_sequence'}]
777 set root2 [db one {SELECT rootpage FROM sqlite_master
779 sqlite3_db_config db DEFENSIVE 0
781 PRAGMA writable_schema=on;
782 UPDATE sqlite_master SET rootpage=$root2
783 WHERE name='sqlite_sequence';
784 UPDATE sqlite_master SET rootpage=$root1
789 set res [catch {db eval {
790 INSERT INTO t1(b) VALUES('two');
793 } {1 {database disk image is malformed}}
795 do_test autoinc-12.5 {
799 sqlite3_db_config db DEFENSIVE 0
801 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
802 INSERT INTO t1(b) VALUES('one');
803 PRAGMA writable_schema=on;
804 UPDATE sqlite_master SET
805 sql='CREATE TABLE sqlite_sequence(x)'
806 WHERE name='sqlite_sequence';
810 set res [catch {db eval {
811 INSERT INTO t1(b) VALUES('two');
814 } {1 {database disk image is malformed}}
815 do_test autoinc-12.6 {
819 sqlite3_db_config db DEFENSIVE 0
821 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
822 INSERT INTO t1(b) VALUES('one');
823 PRAGMA writable_schema=on;
824 UPDATE sqlite_master SET
825 sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)'
826 WHERE name='sqlite_sequence';
830 set res [catch {db eval {
831 INSERT INTO t1(b) VALUES('two'),('three'),('four');
832 INSERT INTO t1(b) VALUES('five');
833 PRAGMA integrity_check;
837 do_test autoinc-12.7 {
841 sqlite3_db_config db DEFENSIVE 0
843 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
844 INSERT INTO t1(b) VALUES('one');
845 PRAGMA writable_schema=on;
846 UPDATE sqlite_master SET
847 sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)'
848 WHERE name='sqlite_sequence';
852 set res [catch {db eval {
853 INSERT INTO t1(b) VALUES('two'),('three'),('four');
854 INSERT INTO t1(b) VALUES('five');
855 PRAGMA integrity_check;
860 #--------------------------------------------------------------------------
862 do_execsql_test 13.0 {
863 CREATE TABLE t1(i INTEGER PRIMARY KEY AUTOINCREMENT, j);
864 CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, j);
865 CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, j);
867 INSERT INTO t1 VALUES(NULL, 1);
868 INSERT INTO t2 VALUES(NULL, 2);
869 INSERT INTO t3 VALUES(NULL, 3);
871 SELECT name FROM sqlite_sequence;
874 do_execsql_test 13.1 {
875 UPDATE sqlite_sequence SET name=NULL WHERE name='t2';
876 INSERT INTO t3 VALUES(NULL, 4);
878 INSERT INTO t3 VALUES(NULL, 5);