drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 1 | # 2008 April 17 |
| 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 focus |
| 12 | # of these tests is the journal mode pragma. |
| 13 | # |
drh | dda70fe | 2009-06-05 17:09:11 +0000 | [diff] [blame] | 14 | # $Id: jrnlmode.test,v 1.16 2009/06/05 17:09:12 drh Exp $ |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | ifcapable {!pager_pragmas} { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | |
danielk1977 | 8a7adb0 | 2008-12-22 11:43:35 +0000 | [diff] [blame] | 24 | if {[info exists TEMP_STORE] && $TEMP_STORE>=2} { |
| 25 | set temp_persist memory |
| 26 | set temp_delete memory |
| 27 | set temp_truncate memory |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 28 | set temp_off off |
danielk1977 | 8a7adb0 | 2008-12-22 11:43:35 +0000 | [diff] [blame] | 29 | } else { |
| 30 | set temp_persist persist |
| 31 | set temp_delete delete |
| 32 | set temp_truncate truncate |
| 33 | set temp_off off |
| 34 | } |
| 35 | |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 36 | proc temp_journal_mode {newmode} { |
| 37 | if {[info exists ::TEMP_STORE] && $::TEMP_STORE>=2} { |
| 38 | if {$newmode ne "off" && $newmode ne "memory"} { |
| 39 | execsql {PRAGMA temp.journal_mode} |
| 40 | set newmode [db one {PRAGMA temp.journal_mode}] |
| 41 | } |
| 42 | } |
| 43 | set newmode |
| 44 | } |
| 45 | |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 46 | #---------------------------------------------------------------------- |
| 47 | # Test cases jrnlmode-1.X test the PRAGMA logic. |
| 48 | # |
| 49 | do_test jrnlmode-1.0 { |
| 50 | execsql { |
| 51 | PRAGMA journal_mode; |
| 52 | PRAGMA main.journal_mode; |
| 53 | PRAGMA temp.journal_mode; |
| 54 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 55 | } [list delete delete [temp_journal_mode delete]] |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 56 | do_test jrnlmode-1.1 { |
| 57 | execsql { |
| 58 | PRAGMA journal_mode = persist; |
| 59 | } |
| 60 | } {persist} |
| 61 | do_test jrnlmode-1.2 { |
| 62 | execsql { |
| 63 | PRAGMA journal_mode; |
| 64 | PRAGMA main.journal_mode; |
| 65 | PRAGMA temp.journal_mode; |
| 66 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 67 | } [list persist persist [temp_journal_mode persist]] |
drh | 6c35b30 | 2019-05-17 20:37:17 +0000 | [diff] [blame] | 68 | do_test jrnlmode-1.4a { |
| 69 | # When defensive is on, unable to set journal_mode to OFF |
| 70 | sqlite3_db_config db DEFENSIVE 1 |
| 71 | execsql { |
| 72 | PRAGMA journal_mode = off; |
| 73 | } |
| 74 | } {persist} |
| 75 | do_test jrnlmode-1.4b { |
| 76 | # When defensive is on, unable to set journal_mode to OFF |
| 77 | sqlite3_db_config db DEFENSIVE 0 |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 78 | execsql { |
| 79 | PRAGMA journal_mode = off; |
| 80 | } |
| 81 | } {off} |
| 82 | do_test jrnlmode-1.5 { |
| 83 | execsql { |
| 84 | PRAGMA journal_mode; |
| 85 | PRAGMA main.journal_mode; |
| 86 | PRAGMA temp.journal_mode; |
| 87 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 88 | } [list off off [temp_journal_mode off]] |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 89 | do_test jrnlmode-1.6 { |
| 90 | execsql { |
| 91 | PRAGMA journal_mode = delete; |
| 92 | } |
| 93 | } {delete} |
| 94 | do_test jrnlmode-1.7 { |
| 95 | execsql { |
| 96 | PRAGMA journal_mode; |
| 97 | PRAGMA main.journal_mode; |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 98 | PRAGMA Temp.journal_mode; |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 99 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 100 | } [list delete delete [temp_journal_mode delete]] |
drh | 0433588 | 2008-09-26 21:08:08 +0000 | [diff] [blame] | 101 | do_test jrnlmode-1.7.1 { |
| 102 | execsql { |
| 103 | PRAGMA journal_mode = truncate; |
| 104 | } |
| 105 | } {truncate} |
| 106 | do_test jrnlmode-1.7.2 { |
| 107 | execsql { |
| 108 | PRAGMA journal_mode; |
| 109 | PRAGMA main.journal_mode; |
| 110 | PRAGMA temp.journal_mode; |
| 111 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 112 | } [list truncate truncate [temp_journal_mode truncate]] |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 113 | do_test jrnlmode-1.8 { |
| 114 | execsql { |
| 115 | PRAGMA journal_mode = off; |
| 116 | PRAGMA journal_mode = invalid; |
| 117 | } |
| 118 | } {off off} |
| 119 | ifcapable attach { |
| 120 | do_test jrnlmode-1.9 { |
| 121 | execsql { |
drh | 0433588 | 2008-09-26 21:08:08 +0000 | [diff] [blame] | 122 | PRAGMA journal_mode = PERSIST; |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 123 | ATTACH ':memory:' as aux1; |
| 124 | } |
| 125 | execsql { |
| 126 | PRAGMA main.journal_mode; |
| 127 | PRAGMA aux1.journal_mode; |
| 128 | } |
danielk1977 | b317538 | 2008-10-17 18:51:52 +0000 | [diff] [blame] | 129 | } {persist memory} |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 130 | do_test jrnlmode-1.10 { |
| 131 | execsql { |
drh | 0433588 | 2008-09-26 21:08:08 +0000 | [diff] [blame] | 132 | PRAGMA main.journal_mode = OFF; |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 133 | } |
| 134 | execsql { |
| 135 | PRAGMA main.journal_mode; |
| 136 | PRAGMA temp.journal_mode; |
| 137 | PRAGMA aux1.journal_mode; |
| 138 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 139 | } [list off [temp_journal_mode persist] memory] |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 140 | do_test jrnlmode-1.11 { |
| 141 | execsql { |
| 142 | PRAGMA journal_mode; |
| 143 | } |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 144 | } {off} |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 145 | do_test jrnlmode-1.12 { |
| 146 | execsql { |
| 147 | ATTACH ':memory:' as aux2; |
| 148 | } |
| 149 | execsql { |
| 150 | PRAGMA main.journal_mode; |
| 151 | PRAGMA aux1.journal_mode; |
| 152 | PRAGMA aux2.journal_mode; |
| 153 | } |
danielk1977 | b317538 | 2008-10-17 18:51:52 +0000 | [diff] [blame] | 154 | } {off memory memory} |
shane | c782f69 | 2008-11-10 19:24:38 +0000 | [diff] [blame] | 155 | do_test jrnlmode-1.13 { |
danielk1977 | b317538 | 2008-10-17 18:51:52 +0000 | [diff] [blame] | 156 | # The journal-mode used by in-memory databases cannot be changed. |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 157 | execsql { |
drh | 0433588 | 2008-09-26 21:08:08 +0000 | [diff] [blame] | 158 | PRAGMA aux1.journal_mode = DELETE; |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 159 | } |
| 160 | execsql { |
| 161 | PRAGMA main.journal_mode; |
| 162 | PRAGMA aux1.journal_mode; |
| 163 | PRAGMA aux2.journal_mode; |
| 164 | } |
danielk1977 | b317538 | 2008-10-17 18:51:52 +0000 | [diff] [blame] | 165 | } {off memory memory} |
shane | c782f69 | 2008-11-10 19:24:38 +0000 | [diff] [blame] | 166 | do_test jrnlmode-1.14 { |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 167 | execsql { |
| 168 | PRAGMA journal_mode = delete; |
| 169 | } |
| 170 | execsql { |
| 171 | PRAGMA main.journal_mode; |
| 172 | PRAGMA temp.journal_mode; |
| 173 | PRAGMA aux1.journal_mode; |
| 174 | PRAGMA aux2.journal_mode; |
| 175 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 176 | } [list delete [temp_journal_mode delete] memory memory] |
shane | c782f69 | 2008-11-10 19:24:38 +0000 | [diff] [blame] | 177 | do_test jrnlmode-1.15 { |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 178 | execsql { |
| 179 | ATTACH ':memory:' as aux3; |
| 180 | } |
| 181 | execsql { |
| 182 | PRAGMA main.journal_mode; |
| 183 | PRAGMA temp.journal_mode; |
| 184 | PRAGMA aux1.journal_mode; |
| 185 | PRAGMA aux2.journal_mode; |
| 186 | PRAGMA aux3.journal_mode; |
| 187 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 188 | } [list delete [temp_journal_mode delete] memory memory memory] |
shane | c782f69 | 2008-11-10 19:24:38 +0000 | [diff] [blame] | 189 | do_test jrnlmode-1.16 { |
drh | 0433588 | 2008-09-26 21:08:08 +0000 | [diff] [blame] | 190 | execsql { |
| 191 | PRAGMA journal_mode = TRUNCATE; |
| 192 | } |
| 193 | execsql { |
| 194 | PRAGMA main.journal_mode; |
| 195 | PRAGMA temp.journal_mode; |
| 196 | PRAGMA aux1.journal_mode; |
| 197 | PRAGMA aux2.journal_mode; |
| 198 | PRAGMA aux3.journal_mode; |
| 199 | } |
danielk1977 | d0f1958 | 2009-04-10 15:02:43 +0000 | [diff] [blame] | 200 | } [list truncate [temp_journal_mode truncate] memory memory memory] |
shane | c782f69 | 2008-11-10 19:24:38 +0000 | [diff] [blame] | 201 | |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 202 | do_test jrnlmode-1.99 { |
| 203 | execsql { |
| 204 | DETACH aux1; |
| 205 | DETACH aux2; |
| 206 | DETACH aux3; |
| 207 | } |
| 208 | } {} |
| 209 | } |
| 210 | |
danielk1977 | df2566a | 2008-05-07 19:11:03 +0000 | [diff] [blame] | 211 | ifcapable attach { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 212 | forcedelete test2.db |
danielk1977 | df2566a | 2008-05-07 19:11:03 +0000 | [diff] [blame] | 213 | do_test jrnlmode-2.1 { |
| 214 | execsql { |
| 215 | ATTACH 'test2.db' AS aux; |
| 216 | PRAGMA main.journal_mode = persist; |
| 217 | PRAGMA aux.journal_mode = persist; |
| 218 | CREATE TABLE abc(a, b, c); |
| 219 | CREATE TABLE aux.def(d, e, f); |
| 220 | } |
| 221 | execsql { |
| 222 | BEGIN; |
| 223 | INSERT INTO abc VALUES(1, 2, 3); |
| 224 | INSERT INTO def VALUES(4, 5, 6); |
| 225 | COMMIT; |
| 226 | } |
| 227 | list [file exists test.db-journal] [file exists test2.db-journal] |
| 228 | } {1 1} |
| 229 | |
| 230 | do_test jrnlmode-2.2 { |
| 231 | file size test.db-journal |
| 232 | } {0} |
| 233 | |
| 234 | do_test jrnlmode-2.3 { |
| 235 | execsql { |
| 236 | SELECT * FROM abc; |
| 237 | } |
| 238 | } {1 2 3} |
| 239 | |
| 240 | do_test jrnlmode-2.4 { |
| 241 | file size test.db-journal |
| 242 | } {0} |
| 243 | |
| 244 | do_test jrnlmode-2.5 { |
| 245 | execsql { |
| 246 | SELECT * FROM def; |
| 247 | } |
| 248 | } {4 5 6} |
| 249 | |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 250 | #---------------------------------------------------------------------- |
| 251 | # Test caes jrnlmode-3.X verify that ticket #3127 has been fixed. |
| 252 | # |
| 253 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 254 | forcedelete test2.db |
| 255 | forcedelete test.db |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 256 | sqlite3 db test.db |
| 257 | |
| 258 | do_test jrnlmode-3.1 { |
| 259 | execsql { |
| 260 | CREATE TABLE x(n INTEGER); |
| 261 | ATTACH 'test2.db' AS a; |
| 262 | create table a.x ( n integer ); |
| 263 | insert into a.x values(1); |
| 264 | insert into a.x values (2); |
| 265 | insert into a.x values (3); |
| 266 | insert into a.x values (4); |
| 267 | } |
| 268 | } {} |
| 269 | |
| 270 | do_test jrnlmode-3.2 { |
| 271 | execsql { PRAGMA journal_mode=off; } |
| 272 | execsql { |
| 273 | BEGIN IMMEDIATE; |
| 274 | INSERT OR IGNORE INTO main.x SELECT * FROM a.x; |
| 275 | COMMIT; |
| 276 | } |
| 277 | } {} |
danielk1977 | df2566a | 2008-05-07 19:11:03 +0000 | [diff] [blame] | 278 | } |
| 279 | |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 280 | ifcapable autovacuum&&pragma { |
| 281 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 282 | forcedelete test.db |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 283 | sqlite3 db test.db |
| 284 | do_test jrnlmode-4.1 { |
| 285 | execsql { |
| 286 | PRAGMA cache_size = 1; |
| 287 | PRAGMA auto_vacuum = 1; |
| 288 | CREATE TABLE abc(a, b, c); |
| 289 | } |
| 290 | execsql { PRAGMA page_count } |
| 291 | } {3} |
danielk1977 | df2566a | 2008-05-07 19:11:03 +0000 | [diff] [blame] | 292 | |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 293 | do_test jrnlmode-4.2 { |
| 294 | execsql { PRAGMA journal_mode = off } |
| 295 | } {off} |
danielk1977 | df2566a | 2008-05-07 19:11:03 +0000 | [diff] [blame] | 296 | |
danielk1977 | 71aa7ff | 2008-05-20 07:05:09 +0000 | [diff] [blame] | 297 | do_test jrnlmode-4.3 { |
| 298 | execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) } |
| 299 | } {} |
| 300 | |
| 301 | # This will attempt to truncate the database file. Check that this |
| 302 | # is not a problem when journal_mode=off. |
| 303 | do_test jrnlmode-4.4 { |
| 304 | execsql { DELETE FROM abc } |
| 305 | } {} |
| 306 | |
| 307 | integrity_check jrnlmode-4.5 |
| 308 | } |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 309 | |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 310 | #------------------------------------------------------------------------ |
| 311 | # The following test caes, jrnlmode-5.*, test the journal_size_limit |
| 312 | # pragma. |
| 313 | ifcapable pragma { |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 314 | if {[atomic_batch_write test.db]==0} { |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 315 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 316 | forcedelete test.db test2.db test3.db |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 317 | sqlite3 db test.db |
| 318 | |
| 319 | do_test jrnlmode-5.1 { |
| 320 | execsql {pragma page_size=1024} |
| 321 | execsql {pragma journal_mode=persist} |
| 322 | } {persist} |
| 323 | |
| 324 | do_test jrnlmode-5.2 { |
| 325 | execsql { PRAGMA journal_size_limit } |
| 326 | } {-1} |
| 327 | do_test jrnlmode-5.3 { |
| 328 | execsql { |
| 329 | ATTACH 'test2.db' AS aux; |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 330 | PRAGMA aux.journal_mode=persist; |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 331 | PRAGMA aux.journal_size_limit; |
| 332 | } |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 333 | } {persist -1} |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 334 | do_test jrnlmode-5.4.1 { |
| 335 | execsql { PRAGMA aux.journal_size_limit = 999999999999 } |
| 336 | } {999999999999} |
| 337 | do_test jrnlmode-5.4.2 { |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 338 | execsql { PRAGMA aux.journal_size_limit = 10240 } |
| 339 | } {10240} |
| 340 | do_test jrnlmode-5.5 { |
| 341 | execsql { PRAGMA main.journal_size_limit = 20480 } |
| 342 | } {20480} |
| 343 | do_test jrnlmode-5.6 { |
| 344 | execsql { PRAGMA journal_size_limit } |
| 345 | } {20480} |
| 346 | do_test jrnlmode-5.7 { |
| 347 | execsql { PRAGMA aux.journal_size_limit } |
| 348 | } {10240} |
| 349 | |
| 350 | do_test jrnlmode-5.8 { |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 351 | execsql { |
| 352 | ATTACH 'test3.db' AS aux2; |
| 353 | PRAGMA aux2.journal_mode=persist; |
| 354 | } |
| 355 | } {persist} |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 356 | |
| 357 | do_test jrnlmode-5.9 { |
| 358 | execsql { |
| 359 | CREATE TABLE main.t1(a, b, c); |
| 360 | CREATE TABLE aux.t2(a, b, c); |
| 361 | CREATE TABLE aux2.t3(a, b, c); |
| 362 | } |
| 363 | } {} |
| 364 | do_test jrnlmode-5.10 { |
| 365 | list \ |
| 366 | [file exists test.db-journal] \ |
| 367 | [file exists test2.db-journal] \ |
| 368 | [file exists test3.db-journal] |
| 369 | } {1 1 1} |
| 370 | do_test jrnlmode-5.11 { |
| 371 | execsql { |
| 372 | BEGIN; |
| 373 | INSERT INTO t3 VALUES(randomblob(1000),randomblob(1000),randomblob(1000)); |
| 374 | INSERT INTO t3 |
| 375 | SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; |
| 376 | INSERT INTO t3 |
| 377 | SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; |
| 378 | INSERT INTO t3 |
| 379 | SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; |
| 380 | INSERT INTO t3 |
| 381 | SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; |
| 382 | INSERT INTO t3 |
| 383 | SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; |
| 384 | INSERT INTO t2 SELECT * FROM t3; |
| 385 | INSERT INTO t1 SELECT * FROM t2; |
| 386 | COMMIT; |
| 387 | } |
| 388 | list \ |
| 389 | [file exists test.db-journal] \ |
| 390 | [file exists test2.db-journal] \ |
| 391 | [file exists test3.db-journal] \ |
| 392 | [file size test.db-journal] \ |
| 393 | [file size test2.db-journal] \ |
| 394 | [file size test3.db-journal] |
| 395 | } {1 1 1 0 0 0} |
| 396 | |
| 397 | do_test jrnlmode-5.12 { |
| 398 | execsql { |
| 399 | BEGIN; |
| 400 | UPDATE t1 SET a = randomblob(1000); |
| 401 | } |
| 402 | expr {[file size test.db-journal]>30000} |
| 403 | } {1} |
| 404 | do_test jrnlmode-5.13 { |
| 405 | execsql COMMIT |
| 406 | file size test.db-journal |
| 407 | } {20480} |
| 408 | |
| 409 | do_test jrnlmode-5.14 { |
| 410 | execsql { |
| 411 | BEGIN; |
| 412 | UPDATE t2 SET a = randomblob(1000); |
| 413 | } |
| 414 | expr {[file size test2.db-journal]>30000} |
| 415 | } {1} |
| 416 | do_test jrnlmode-5.15 { |
| 417 | execsql COMMIT |
| 418 | file size test2.db-journal |
| 419 | } {10240} |
| 420 | |
| 421 | do_test jrnlmode-5.16 { |
| 422 | execsql { |
| 423 | BEGIN; |
| 424 | UPDATE t3 SET a = randomblob(1000); |
| 425 | } |
| 426 | set journalsize [file size test3.db-journal] |
| 427 | expr {$journalsize>30000} |
| 428 | } {1} |
| 429 | do_test jrnlmode-5.17 { |
| 430 | execsql COMMIT |
drh | e6a6464 | 2008-08-02 20:09:36 +0000 | [diff] [blame] | 431 | set sz [file size test3.db-journal] |
| 432 | expr {$sz>=$journalsize} |
| 433 | } {1} |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 434 | |
| 435 | do_test jrnlmode-5.18 { |
| 436 | execsql { |
| 437 | PRAGMA journal_size_limit = -4; |
| 438 | BEGIN; |
| 439 | UPDATE t1 SET a = randomblob(1000); |
| 440 | } |
| 441 | set journalsize [file size test.db-journal] |
| 442 | expr {$journalsize>30000} |
| 443 | } {1} |
| 444 | do_test jrnlmode-5.19 { |
| 445 | execsql COMMIT |
drh | e6a6464 | 2008-08-02 20:09:36 +0000 | [diff] [blame] | 446 | set sz [file size test.db-journal] |
| 447 | expr {$sz>=$journalsize} |
| 448 | } {1} |
danielk1977 | 7cbd589 | 2009-01-10 16:15:09 +0000 | [diff] [blame] | 449 | |
| 450 | # Test a size-limit of 0. |
| 451 | # |
| 452 | do_test jrnlmode-5.20 { |
| 453 | execsql { |
| 454 | PRAGMA journal_size_limit = 0; |
| 455 | BEGIN; |
| 456 | UPDATE t1 SET a = randomblob(1000); |
| 457 | } |
| 458 | } {0} |
| 459 | do_test jrnlmode-5.21 { |
| 460 | expr {[file size test.db-journal] > 1024} |
| 461 | } {1} |
| 462 | do_test jrnlmode-5.22 { |
| 463 | execsql COMMIT |
| 464 | list [file exists test.db-journal] [file size test.db-journal] |
| 465 | } {1 0} |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 466 | } |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 467 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 468 | |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 469 | ifcapable pragma { |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 470 | if {[atomic_batch_write test.db]==0} { |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 471 | # These tests are not run as part of the "journaltest" permutation, |
| 472 | # as the test_journal.c layer is incompatible with in-memory journaling. |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 473 | if {[permutation] ne "journaltest"} { |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 474 | |
| 475 | do_test jrnlmode-6.1 { |
| 476 | execsql { |
| 477 | PRAGMA journal_mode = truncate; |
| 478 | CREATE TABLE t4(a, b); |
| 479 | BEGIN; |
| 480 | INSERT INTO t4 VALUES(1, 2); |
| 481 | PRAGMA journal_mode = memory; |
| 482 | } |
drh | 8a93919 | 2009-04-20 17:43:03 +0000 | [diff] [blame] | 483 | } {truncate truncate} |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 484 | do_test jrnlmode-6.2 { |
| 485 | file exists test.db-journal |
| 486 | } {1} |
| 487 | do_test jrnlmode-6.3 { |
| 488 | execsql { |
| 489 | COMMIT; |
| 490 | SELECT * FROM t4; |
| 491 | } |
| 492 | } {1 2} |
| 493 | do_test jrnlmode-6.4 { |
| 494 | file exists test.db-journal |
drh | 8a93919 | 2009-04-20 17:43:03 +0000 | [diff] [blame] | 495 | } {1} |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 496 | do_test jrnlmode-6.5 { |
| 497 | execsql { |
drh | 8a93919 | 2009-04-20 17:43:03 +0000 | [diff] [blame] | 498 | PRAGMA journal_mode = MEMORY; |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 499 | BEGIN; |
| 500 | INSERT INTO t4 VALUES(3, 4); |
| 501 | } |
| 502 | file exists test.db-journal |
dan | be5c104 | 2010-06-17 17:05:53 +0000 | [diff] [blame] | 503 | } {0} |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 504 | do_test jrnlmode-6.7 { |
| 505 | execsql { |
| 506 | COMMIT; |
| 507 | SELECT * FROM t4; |
| 508 | } |
| 509 | } {1 2 3 4} |
| 510 | do_test jrnlmode-6.8 { |
| 511 | file exists test.db-journal |
dan | be5c104 | 2010-06-17 17:05:53 +0000 | [diff] [blame] | 512 | } {0} |
drh | 8a93919 | 2009-04-20 17:43:03 +0000 | [diff] [blame] | 513 | do_test jrnlmode-6.9 { |
| 514 | execsql { |
| 515 | PRAGMA journal_mode = DELETE; |
drh | ba726f4 | 2010-03-19 15:48:13 +0000 | [diff] [blame] | 516 | BEGIN IMMEDIATE; INSERT INTO t4 VALUES(1,2); COMMIT; |
drh | 8a93919 | 2009-04-20 17:43:03 +0000 | [diff] [blame] | 517 | } |
| 518 | file exists test.db-journal |
danielk1977 | c499bf1 | 2009-01-11 05:54:40 +0000 | [diff] [blame] | 519 | } {0} |
| 520 | } |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 521 | } |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 522 | } |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 523 | |
dan | 3f94b60 | 2010-07-03 13:45:52 +0000 | [diff] [blame] | 524 | ifcapable pragma { |
| 525 | catch { db close } |
| 526 | do_test jrnlmode-7.1 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 527 | foreach f [glob -nocomplain test.db*] { forcedelete $f } |
dan | 3f94b60 | 2010-07-03 13:45:52 +0000 | [diff] [blame] | 528 | sqlite3 db test.db |
| 529 | execsql { |
| 530 | PRAGMA journal_mode = memory; |
| 531 | PRAGMA auto_vacuum = 0; |
| 532 | PRAGMA page_size = 1024; |
| 533 | PRAGMA user_version = 5; |
| 534 | PRAGMA user_version; |
| 535 | } |
| 536 | } {memory 5} |
| 537 | do_test jrnlmode-7.2 { file size test.db } {1024} |
| 538 | } |
| 539 | |
dan | e5953cc | 2010-08-07 09:31:14 +0000 | [diff] [blame] | 540 | do_execsql_test jrnlmode-8.1 { PRAGMA locking_mode=EXCLUSIVE } {exclusive} |
| 541 | do_execsql_test jrnlmode-8.2 { CREATE TABLE t1(x) } {} |
| 542 | do_execsql_test jrnlmode-8.3 { INSERT INTO t1 VALUES(123) } {} |
| 543 | do_execsql_test jrnlmode-8.4 { SELECT * FROM t1 } {123} |
| 544 | do_execsql_test jrnlmode-8.5 { PRAGMA journal_mode=PERSIST } {persist} |
| 545 | do_execsql_test jrnlmode-8.6 { PRAGMA journal_mode=DELETE } {delete} |
| 546 | do_execsql_test jrnlmode-8.7 { PRAGMA journal_mode=TRUNCATE } {truncate} |
| 547 | do_execsql_test jrnlmode-8.8 { PRAGMA journal_mode=DELETE } {delete} |
| 548 | do_execsql_test jrnlmode-8.9 { CREATE TABLE t2(y) } {} |
| 549 | do_execsql_test jrnlmode-8.10 { INSERT INTO t2 VALUES(456) } {} |
| 550 | do_execsql_test jrnlmode-8.11 { SELECT * FROM t1, t2 } {123 456} |
| 551 | do_execsql_test jrnlmode-8.12 { PRAGMA locking_mode=NORMAL } {normal} |
| 552 | do_execsql_test jrnlmode-8.13 { PRAGMA journal_mode=PERSIST } {persist} |
| 553 | do_execsql_test jrnlmode-8.14 { PRAGMA journal_mode=TRUNCATE } {truncate} |
| 554 | do_execsql_test jrnlmode-8.15 { PRAGMA journal_mode=PERSIST } {persist} |
| 555 | do_execsql_test jrnlmode-8.16 { PRAGMA journal_mode=DELETE } {delete} |
| 556 | do_execsql_test jrnlmode-8.17 { PRAGMA journal_mode=TRUNCATE } {truncate} |
| 557 | do_execsql_test jrnlmode-8.18 { PRAGMA locking_mode=EXCLUSIVE } {exclusive} |
| 558 | do_execsql_test jrnlmode-8.19 { CREATE TABLE t3(z) } {} |
| 559 | do_execsql_test jrnlmode-8.20 { BEGIN IMMEDIATE } {} |
| 560 | do_execsql_test jrnlmode-8.21 { PRAGMA journal_mode=DELETE } {delete} |
| 561 | do_execsql_test jrnlmode-8.22 { COMMIT } {} |
| 562 | do_execsql_test jrnlmode-8.23 { PRAGMA journal_mode=DELETE } {delete} |
| 563 | do_execsql_test jrnlmode-8.24 { PRAGMA journal_mode=TRUNCATE } {truncate} |
| 564 | do_execsql_test jrnlmode-8.25 { PRAGMA locking_mode=NORMAL } {normal} |
| 565 | do_execsql_test jrnlmode-8.26 { CREATE TABLE t4(w) } {} |
| 566 | do_execsql_test jrnlmode-8.27 { BEGIN IMMEDIATE } {} |
| 567 | do_execsql_test jrnlmode-8.28 { PRAGMA journal_mode=DELETE } {delete} |
| 568 | do_execsql_test jrnlmode-8.29 { COMMIT } {} |
| 569 | do_execsql_test jrnlmode-8.30 { PRAGMA journal_mode=DELETE } {delete} |
| 570 | |
dan | 929b923 | 2015-05-01 16:57:24 +0000 | [diff] [blame] | 571 | # Assertion fault on 2015-05-01 |
| 572 | do_test jrnlmode-9.1 { |
| 573 | forcedelete test2.db |
| 574 | sqlite3 db2 test2.db |
dan | 929b923 | 2015-05-01 16:57:24 +0000 | [diff] [blame] | 575 | db2 eval {CREATE TEMP TABLE t(l); PRAGMA journal_mode=off;} |
| 576 | db2 close |
| 577 | } {} |
| 578 | do_execsql_test jrnlmode-9.2 { |
| 579 | PRAGMA locking_mode = exclusive; |
| 580 | CREATE TABLE tx(a); |
| 581 | PRAGMA journal_mode = off; |
| 582 | } {exclusive off} |
| 583 | |
| 584 | |
drh | 16e45a4 | 2008-04-19 20:34:18 +0000 | [diff] [blame] | 585 | finish_test |