Add the json_pretty(J) function for pretty-printing of JSON. An optional
[sqlite.git] / test / vacuum-into.test
blob698d65f5406baed4ef690ca9c98da7c54dc24290
1 # 2018-12-07
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.
21 ifcapable {!vacuum} {
22   omit_test vacuum.test {Compiled with SQLITE_OMIT_VACUUM}
23   finish_test
24   return
27 forcedelete out.db
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;
35 } {50 2550 30000}
36 do_execsql_test vacuum-into-110 {
37   VACUUM main INTO 'out.db';
38 } {}
39 sqlite3 db2 out.db
40 do_test vacuum-into-120 {
41   db2 eval {SELECT count(*), sum(a), sum(length(b)) FROM t1}
42 } {50 2550 30000}
43 do_catchsql_test vacuum-into-130 {
44   VACUUM INTO 'out.db';
45 } {1 {output file already exists}}
46 forcedelete out2.db
47 do_catchsql_test vacuum-into-140 {
48   VACUUM INTO 'out2.db';
49 } {0 {}}
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:';
56 } {0 {}}
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);
64 } {}
65 do_catchsql_test vacuum-into-310 {
66   VACUUM INTO null;
67 } {1 {non-text filename}}
68 do_catchsql_test vacuum-into-320 {
69   VACUUM INTO x;
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}}
78 forcedelete test.db2
79 db func target target
80 proc target {} { return "test.db2" }
81 do_test vacuum-into-410 {
82   execsql { VACUUM INTO target() }
83   file exists test.db2
84 } 1
85 do_catchsql_test vacuum-into-420 {
86   VACUUM INTO target2()
87 } {1 {no such function: target2}}
89 # The ability to VACUUM INTO a read-only database
90 db close
91 sqlite3 db test.db -readonly 1
92 forcedelete test.db2
93 do_execsql_test vacuum-into-500 {
94   VACUUM INTO 'test.db2';
96 sqlite3 db2 test.db2
97 do_test vacuum-into-510 {
98   db2 eval {SELECT name FROM sqlite_master ORDER BY 1}
99 } {t1 t1b t2}
100 db2 close
101 db close
103 # Change the page-size on a VACUUM INTO even if the original
104 # database is in WAL mode.
106 if {[wal_is_capable]} {
107   forcedelete test.db
108   forcedelete test.db2
109   do_test vacuum-into-600 {
110     sqlite3 db test.db
111     db eval {
112       PRAGMA page_size=4096;
113       PRAGMA journal_mode=WAL;
114       CREATE TABLE t1(a);
115       INSERT INTO t1 VALUES(19);
116       CREATE INDEX t1a ON t1(a);
117       PRAGMA integrity_check;
118     }
119   } {wal ok}
120   do_execsql_test vacuum-into-610 {
121     PRAGMA page_size;
122   } {4096}
123   do_execsql_test vacuum-into-620 {
124     PRAGMA page_size=1024;
125     VACUUM INTO 'test.db2';
126   } {}
127   do_test vacuum-into-630 {
128     sqlite3 db test.db2
129     db eval {
130       PRAGMA page_size;
131       PRAGMA integrity_check;
132     }
133   } {1024 ok}
136 #-------------------------------------------------------------------------
138 testvfs tvfs -default 1
139 tvfs filter xSync
140 tvfs script xSyncCb
141 proc xSyncCb {method file fileid flags} {
142   incr ::sync($flags)
145 reset_db
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} {
153   710 {
154     PRAGMA synchronous = normal
155   } {normal 2}
156   720 {
157     PRAGMA synchronous = full
158   } {normal 3}
159   730 {
160     PRAGMA synchronous = off
161   } {}
162   740 {
163     PRAGMA synchronous = extra;
164   } {normal 3}
165   750 {
166     PRAGMA fullfsync = 1;
167     PRAGMA synchronous = full;
168   } {full|dataonly 1 full 2}
169 } {
171   forcedelete test.db2
172   array unset ::sync
173   do_execsql_test vacuum-into-$tn.1 "
174     $pragma ;
175     VACUUM INTO 'test.db2'
176   "
178   do_test vacuum-into-$tn.2 {
179     array get ::sync
180   } $res
183 db close
184 tvfs delete
187 finish_test