AryaWu/sqlite
0
1# 2016 September 102#3# The author disclaims copyright to this source code. In place of4# 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. The12# focus of this file is testing the code in test_delete.c (the13# sqlite3_delete_database() API).14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18set testprefix delete_db19 20if {[atomic_batch_write test.db]} {21 finish_test22 return23}24 25proc delete_all {} {26 foreach f [glob -nocomplain test2*] { file delete $f }27 foreach f [glob -nocomplain test3*] { file delete $f }28}29 30proc copydb {} {31 foreach f [glob -nocomplain test3*] { file delete $f }32 foreach f [glob -nocomplain test2*] { 33 set p [string range $f 5 end]34 file copy "test2$p" "test3$p"35 }36}37 38proc files {} {39 lsort [glob -nocomplain test3*]40}41 42db close43delete_all44sqlite3 db test2.database45 46#-------------------------------------------------------------------------47#48# 1.1: Journal files.49# 1.2: Wal files.50# 1.3: Multiplexor with journal file.51# 1.4: Multiplexor with wal file.52#53# 2.* are a copy of 1.* with the multiplexor enabled.54#55# 3.* tests errors.56#57 58do_test 1.1.0 {59 execsql {60 CREATE TABLE t1(x, y);61 BEGIN;62 INSERT INTO t1 VALUES(1, 2);63 }64 copydb65 files66} {test3.database test3.database-journal}67 68do_test 1.1.1 {69 sqlite3_delete_database test3.database70 files71} {}72 73do_test 1.2.0 {74 execsql {75 COMMIT;76 PRAGMA journal_mode = wal;77 INSERT INTO t1 VALUES(3, 4);78 }79 copydb80 files81} {test3.database test3.database-shm test3.database-wal}82do_test 1.2.1 {83 sqlite3_delete_database test3.database84 files85} {}86 87db close88delete_all89sqlite3_multiplex_initialize "" 090sqlite3 db test2.database -vfs multiplex91sqlite3_multiplex_control db "main" chunk_size 3276892 93do_test 1.3.0 {94 execsql { PRAGMA auto_vacuum = 0; }95 execsql {96 CREATE TABLE x1(a, b);97 WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 )98 INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s;99 BEGIN;100 UPDATE x1 SET a=randomblob(101)101 }102 copydb103 files104} [list {*}{105 test3.database test3.database-journal test3.database001 106 test3.database002 test3.database003107}]108do_test 1.3.1 {109 sqlite3_delete_database test3.database110 files111} {}112 113 114do_test 1.4.0 {115 execsql {116 COMMIT;117 PRAGMA journal_mode = wal;118 UPDATE x1 SET a=randomblob(102)119 }120 copydb121 files122} [list {*}{123 test3.database test3.database-shm test3.database-wal test3.database001 124 test3.database002 test3.database003125}]126do_test 1.4.1 {127 sqlite3_delete_database test3.database128 files129} {}130 131 132ifcapable 8_3_names {133 db close134 delete_all135 sqlite3 db file:test2.db?8_3_names=1 -uri 1136 137 do_test 2.1.0 {138 execsql {139 CREATE TABLE t1(x, y);140 BEGIN;141 INSERT INTO t1 VALUES(1, 2);142 }143 copydb144 files145 } {test3.db test3.nal}146 147 do_test 2.1.1 {148 sqlite3_delete_database test3.db149 files150 } {}151 152 do_test 2.2.0 {153 execsql {154 COMMIT;155 PRAGMA journal_mode = wal;156 INSERT INTO t1 VALUES(3, 4);157 }158 copydb159 files160 } {test3.db test3.shm test3.wal}161 do_test 2.2.1 {162 sqlite3_delete_database test3.db163 files164 } {}165 166 167 db close168 delete_all169 sqlite3_multiplex_initialize "" 0170 sqlite3 db file:test2.db?8_3_names=1 -uri 1 -vfs multiplex171 sqlite3_multiplex_control db "main" chunk_size 32768172 173 do_test 2.3.0 {174 execsql { PRAGMA auto_vacuum = 0; }175 execsql {176 CREATE TABLE x1(a, b);177 WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 )178 INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s;179 BEGIN;180 UPDATE x1 SET a=randomblob(101)181 }182 copydb183 files184 } [list {*}{185 test3.001 test3.002 test3.003 test3.db test3.nal 186 }]187 do_test 2.3.1 {188 sqlite3_delete_database test3.db189 files190 } {}191 192 193 do_test 2.4.0 {194 execsql {195 COMMIT;196 PRAGMA journal_mode = wal;197 UPDATE x1 SET a=randomblob(102)198 }199 copydb200 files201 } [list {*}{202 test3.001 test3.002 test3.003 test3.db test3.db-shm test3.wal 203 }]204 do_test 2.4.1 {205 sqlite3_delete_database test3.db206 files207 } {}208}209 210db close211delete_all212sqlite3_multiplex_shutdown 213 214do_test 3.0 {215 file mkdir dir2.db216 sqlite3_delete_database dir2.db217} {SQLITE_ERROR}218do_test 3.1 {219 sqlite3_delete_database dir2.db/test.db220} {SQLITE_OK}221 222finish_test223 