gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/vacuum-into.test (about) 1 # 2018-12-07 2 # 3 # The author disclaims copyright to this source code. In place of 4 # a legal notice, here is a blessing: 5 # 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. 9 # 10 #*********************************************************************** 11 # This file implements regression tests for SQLite library. The 12 # focus of this file is testing the VACUUM INTO statement. 13 # 14 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 18 # If the VACUUM statement is disabled in the current build, skip all 19 # the tests in this file. 20 # 21 ifcapable {!vacuum} { 22 omit_test vacuum.test {Compiled with SQLITE_OMIT_VACUUM} 23 finish_test 24 return 25 } 26 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}} 53 54 do_catchsql_test vacuum-into-200 { 55 VACUUM main INTO ':memory:'; 56 } {0 {}} 57 58 # The INTO argument can be an arbitrary expression. 59 # 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}} 77 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}} 88 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'; 95 } 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 102 103 # Change the page-size on a VACUUM INTO even if the original 104 # database is in WAL mode. 105 # 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} 134 } 135 136 finish_test