1# 2016 September 10 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 code in test_delete.c (the 13# sqlite3_delete_database() API). 14# 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18set testprefix delete_db 19 20proc delete_all {} { 21 foreach f [glob -nocomplain test2*] { file delete $f } 22 foreach f [glob -nocomplain test3*] { file delete $f } 23} 24 25proc copydb {} { 26 foreach f [glob -nocomplain test3*] { file delete $f } 27 foreach f [glob -nocomplain test2*] { 28 set p [string range $f 5 end] 29 file copy "test2$p" "test3$p" 30 } 31} 32 33proc files {} { 34 lsort [glob -nocomplain test3*] 35} 36 37db close 38delete_all 39sqlite3 db test2.database 40 41#------------------------------------------------------------------------- 42# 43# 1.1: Journal files. 44# 1.2: Wal files. 45# 1.3: Multiplexor with journal file. 46# 1.4: Multiplexor with wal file. 47# 48# 2.* are a copy of 1.* with the multiplexor enabled. 49# 50# 3.* tests errors. 51# 52 53do_test 1.1.0 { 54 execsql { 55 CREATE TABLE t1(x, y); 56 BEGIN; 57 INSERT INTO t1 VALUES(1, 2); 58 } 59 copydb 60 files 61} {test3.database test3.database-journal} 62 63do_test 1.1.1 { 64 sqlite3_delete_database test3.database 65 files 66} {} 67 68do_test 1.2.0 { 69 execsql { 70 COMMIT; 71 PRAGMA journal_mode = wal; 72 INSERT INTO t1 VALUES(3, 4); 73 } 74 copydb 75 files 76} {test3.database test3.database-shm test3.database-wal} 77do_test 1.2.1 { 78 sqlite3_delete_database test3.database 79 files 80} {} 81 82db close 83delete_all 84sqlite3_multiplex_initialize "" 0 85sqlite3 db test2.database -vfs multiplex 86sqlite3_multiplex_control db "main" chunk_size 32768 87 88do_test 1.3.0 { 89 execsql { PRAGMA auto_vacuum = 0; } 90 execsql { 91 CREATE TABLE x1(a, b); 92 WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) 93 INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; 94 BEGIN; 95 UPDATE x1 SET a=randomblob(101) 96 } 97 copydb 98 files 99} [list {*}{ 100 test3.database test3.database-journal test3.database001 101 test3.database002 test3.database003 102}] 103do_test 1.3.1 { 104 sqlite3_delete_database test3.database 105 files 106} {} 107 108 109do_test 1.4.0 { 110 execsql { 111 COMMIT; 112 PRAGMA journal_mode = wal; 113 UPDATE x1 SET a=randomblob(102) 114 } 115 copydb 116 files 117} [list {*}{ 118 test3.database test3.database-shm test3.database-wal test3.database001 119 test3.database002 test3.database003 120}] 121do_test 1.4.1 { 122 sqlite3_delete_database test3.database 123 files 124} {} 125 126 127ifcapable 8_3_names { 128 db close 129 delete_all 130 sqlite3 db file:test2.db?8_3_names=1 -uri 1 131 132 do_test 2.1.0 { 133 execsql { 134 CREATE TABLE t1(x, y); 135 BEGIN; 136 INSERT INTO t1 VALUES(1, 2); 137 } 138 copydb 139 files 140 } {test3.db test3.nal} 141 142 do_test 2.1.1 { 143 sqlite3_delete_database test3.db 144 files 145 } {} 146 147 do_test 2.2.0 { 148 execsql { 149 COMMIT; 150 PRAGMA journal_mode = wal; 151 INSERT INTO t1 VALUES(3, 4); 152 } 153 copydb 154 files 155 } {test3.db test3.shm test3.wal} 156 do_test 2.2.1 { 157 sqlite3_delete_database test3.db 158 files 159 } {} 160 161 162 db close 163 delete_all 164 sqlite3_multiplex_initialize "" 0 165 sqlite3 db file:test2.db?8_3_names=1 -uri 1 -vfs multiplex 166 sqlite3_multiplex_control db "main" chunk_size 32768 167 168 do_test 2.3.0 { 169 execsql { PRAGMA auto_vacuum = 0; } 170 execsql { 171 CREATE TABLE x1(a, b); 172 WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) 173 INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; 174 BEGIN; 175 UPDATE x1 SET a=randomblob(101) 176 } 177 copydb 178 files 179 } [list {*}{ 180 test3.001 test3.002 test3.003 test3.db test3.nal 181 }] 182 do_test 2.3.1 { 183 sqlite3_delete_database test3.db 184 files 185 } {} 186 187 188 do_test 2.4.0 { 189 execsql { 190 COMMIT; 191 PRAGMA journal_mode = wal; 192 UPDATE x1 SET a=randomblob(102) 193 } 194 copydb 195 files 196 } [list {*}{ 197 test3.001 test3.002 test3.003 test3.db test3.db-shm test3.wal 198 }] 199 do_test 2.4.1 { 200 sqlite3_delete_database test3.db 201 files 202 } {} 203} 204 205db close 206delete_all 207sqlite3_multiplex_shutdown 208 209do_test 3.0 { 210 file mkdir dir2.db 211 sqlite3_delete_database dir2.db 212} {SQLITE_ERROR} 213do_test 3.1 { 214 sqlite3_delete_database dir2.db/test.db 215} {SQLITE_OK} 216 217finish_test 218