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.
15 # $Id: createtab.test,v 1.3 2007/09/12 17:01:45 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 ifcapable autovacuum {
26 # Run these tests for all possible values of autovacuum.
28 for {set av 0} {$av<=$upperBound} {incr av} {
30 forcedelete test.db test.db-journal
33 # Create a table that spans multiple pages. It is important
34 # that part of the database be in pages beyond the root page.
36 do_test createtab-$av.1 {
37 execsql "PRAGMA auto_vacuum=$av"
39 PRAGMA page_size=1024;
40 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
41 INSERT INTO t1 VALUES(1, hex(randomblob(200)));
42 INSERT INTO t1 VALUES(2, hex(randomblob(200)));
43 INSERT INTO t1 VALUES(3, hex(randomblob(200)));
44 INSERT INTO t1 VALUES(4, hex(randomblob(200)));
45 SELECT count(*) FROM t1;
51 set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}]
54 do_test createtab-$av.2 {
56 } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}]
58 # Start reading the table
60 do_test createtab-$av.3 {
61 set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL]
64 do_test createtab-$av.4 {
65 sqlite3_column_int $STMT 0
68 # While still reading the table, create a new table.
70 do_test createtab-$av.5 {
73 INSERT INTO t2 VALUES(1,2);
78 # Continue reading the original table.
80 do_test createtab-$av.6 {
81 sqlite3_column_int $STMT 0
83 do_test createtab-$av.7 {
86 do_test createtab-$av.8 {
87 sqlite3_column_int $STMT 0
90 # Do another cycle of creating a new database table while contining
91 # to read the original table.
93 do_test createtab-$av.11 {
96 INSERT INTO t3 VALUES(4,5);
100 do_test createtab-$av.12 {
101 sqlite3_column_int $STMT 0
103 do_test createtab-$av.13 {
106 do_test createtab-$av.14 {
107 sqlite3_column_int $STMT 0
112 do_test createtab-$av.21 {
114 CREATE TABLE t4(a,b);
115 INSERT INTO t4 VALUES('abc','xyz');
119 do_test createtab-$av.22 {
120 sqlite3_column_int $STMT 0
122 do_test createtab-$av.23 {
125 do_test createtab-$av.24 {
126 sqlite3_column_int $STMT 0
129 # Finish reading. Do an integrity check on the database.
131 do_test createtab-$av.30 {
134 do_test createtab-$av.31 {
135 sqlite3_finalize $STMT
137 do_test createtab-$av.32 {
139 SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1
142 integrity_check createtab-$av.40