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 file is testing that it is OK to create new tables
13 # and indices while creating existing tables and indices.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable autovacuum {
25 # Run these tests for all possible values of autovacuum.
27 for {set av 0} {$av<=$upperBound} {incr av} {
29 forcedelete test.db test.db-journal
32 # Create a table that spans multiple pages. It is important
33 # that part of the database be in pages beyond the root page.
35 do_test createtab-$av.1 {
36 execsql "PRAGMA auto_vacuum=$av"
38 PRAGMA page_size=1024;
39 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
40 INSERT INTO t1 VALUES(1, hex(randomblob(200)));
41 INSERT INTO t1 VALUES(2, hex(randomblob(200)));
42 INSERT INTO t1 VALUES(3, hex(randomblob(200)));
43 INSERT INTO t1 VALUES(4, hex(randomblob(200)));
44 SELECT count(*) FROM t1;
50 set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}]
53 do_test createtab-$av.2 {
55 } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}]
57 # Start reading the table
59 do_test createtab-$av.3 {
60 set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL]
63 do_test createtab-$av.4 {
64 sqlite3_column_int $STMT 0
67 # While still reading the table, create a new table.
69 do_test createtab-$av.5 {
72 INSERT INTO t2 VALUES(1,2);
77 # Continue reading the original table.
79 do_test createtab-$av.6 {
80 sqlite3_column_int $STMT 0
82 do_test createtab-$av.7 {
85 do_test createtab-$av.8 {
86 sqlite3_column_int $STMT 0
89 # Do another cycle of creating a new database table while contining
90 # to read the original table.
92 do_test createtab-$av.11 {
95 INSERT INTO t3 VALUES(4,5);
99 do_test createtab-$av.12 {
100 sqlite3_column_int $STMT 0
102 do_test createtab-$av.13 {
105 do_test createtab-$av.14 {
106 sqlite3_column_int $STMT 0
111 do_test createtab-$av.21 {
113 CREATE TABLE t4(a,b);
114 INSERT INTO t4 VALUES('abc','xyz');
118 do_test createtab-$av.22 {
119 sqlite3_column_int $STMT 0
121 do_test createtab-$av.23 {
124 do_test createtab-$av.24 {
125 sqlite3_column_int $STMT 0
128 # Finish reading. Do an integrity check on the database.
130 do_test createtab-$av.30 {
133 do_test createtab-$av.31 {
134 sqlite3_finalize $STMT
136 do_test createtab-$av.32 {
138 SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1
141 integrity_check createtab-$av.40
145 # 2019-03-31 Ensure that a proper error is returned for an index
146 # with too many columns.
148 do_test createtab-3.1 {
149 db eval {DROP TABLE IF EXISTS t1;}
150 set sql "CREATE TABLE t1(x,UNIQUE(x[string repeat ,x 100000]))"
152 } {1 {too many columns in index}}