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 the VACUUM INTO statement.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 # If the VACUUM statement is disabled in the current build, skip all
19 # the tests in this file.
22 omit_test vacuum.test {Compiled with SQLITE_OMIT_VACUUM}
28 do_execsql_test vacuum-into-100 {
29 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
30 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
31 INSERT INTO t1(a,b) SELECT x, randomblob(600) FROM c;
32 CREATE INDEX t1b ON t1(b);
33 DELETE FROM t1 WHERE a%2;
34 SELECT count(*), sum(a), sum(length(b)) FROM t1;
36 do_execsql_test vacuum-into-110 {
37 VACUUM main INTO 'out.db';
40 do_test vacuum-into-120 {
41 db2 eval {SELECT count(*), sum(a), sum(length(b)) FROM t1}
43 do_catchsql_test vacuum-into-130 {
45 } {1 {output file already exists}}
47 do_catchsql_test vacuum-into-140 {
48 VACUUM INTO 'out2.db';
50 do_catchsql_test vacuum-into-150 {
51 VACUUM INTO 'out2.db';
52 } {1 {output file already exists}}
54 do_catchsql_test vacuum-into-200 {
55 VACUUM main INTO ':memory:';
58 # The INTO argument can be an arbitrary expression.
60 do_execsql_test vacuum-into-300 {
61 CREATE TABLE t2(name TEXT);
62 INSERT INTO t2 VALUES(':memory:');
63 VACUUM main INTO (SELECT name FROM t2);
65 do_catchsql_test vacuum-into-310 {
67 } {1 {non-text filename}}
68 do_catchsql_test vacuum-into-320 {
70 } {1 {no such column: x}}
71 do_catchsql_test vacuum-into-330 {
72 VACUUM INTO t1.nosuchcol;
73 } {1 {no such column: t1.nosuchcol}}
74 do_catchsql_test vacuum-into-340 {
75 VACUUM INTO main.t1.nosuchcol;
76 } {1 {no such column: main.t1.nosuchcol}}
80 proc target {} { return "test.db2" }
81 do_test vacuum-into-410 {
82 execsql { VACUUM INTO target() }
85 do_catchsql_test vacuum-into-420 {
87 } {1 {no such function: target2}}
89 # The ability to VACUUM INTO a read-only database
91 sqlite3 db test.db -readonly 1
93 do_execsql_test vacuum-into-500 {
94 VACUUM INTO 'test.db2';
97 do_test vacuum-into-510 {
98 db2 eval {SELECT name FROM sqlite_master ORDER BY 1}
103 # Change the page-size on a VACUUM INTO even if the original
104 # database is in WAL mode.
106 if {[wal_is_capable]} {
109 do_test vacuum-into-600 {
112 PRAGMA page_size=4096;
113 PRAGMA journal_mode=WAL;
115 INSERT INTO t1 VALUES(19);
116 CREATE INDEX t1a ON t1(a);
117 PRAGMA integrity_check;
120 do_execsql_test vacuum-into-610 {
123 do_execsql_test vacuum-into-620 {
124 PRAGMA page_size=1024;
125 VACUUM INTO 'test.db2';
127 do_test vacuum-into-630 {
131 PRAGMA integrity_check;
136 #-------------------------------------------------------------------------
138 testvfs tvfs -default 1
141 proc xSyncCb {method file fileid flags} {
147 do_execsql_test vacuum-into-700 {
148 CREATE TABLE t1(a, b);
149 INSERT INTO t1 VALUES(1, 2);
152 foreach {tn pragma res} {
154 PRAGMA synchronous = normal
157 PRAGMA synchronous = full
160 PRAGMA synchronous = off
163 PRAGMA synchronous = extra;
166 PRAGMA fullfsync = 1;
167 PRAGMA synchronous = full;
168 } {full|dataonly 1 full 2}
173 do_execsql_test vacuum-into-$tn.1 "
175 VACUUM INTO 'test.db2'
178 do_test vacuum-into-$tn.2 {