Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: third_party/sqlite/src/test/walbak.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2010 April 22 1 # 2010 April 22
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
(...skipping 30 matching lines...) Expand all
41 PRAGMA page_size = 1024; 41 PRAGMA page_size = 1024;
42 PRAGMA auto_vacuum = 0; 42 PRAGMA auto_vacuum = 0;
43 PRAGMA journal_mode = wal; 43 PRAGMA journal_mode = wal;
44 BEGIN; 44 BEGIN;
45 CREATE TABLE t1(a PRIMARY KEY, b); 45 CREATE TABLE t1(a PRIMARY KEY, b);
46 INSERT INTO t1 VALUES('I', 'one'); 46 INSERT INTO t1 VALUES('I', 'one');
47 COMMIT; 47 COMMIT;
48 } 48 }
49 } {wal} 49 } {wal}
50 do_test walbak-1.1 { 50 do_test walbak-1.1 {
51 file delete -force bak.db bak.db-journal bak.db-wal 51 forcedelete bak.db bak.db-journal bak.db-wal
52 db backup bak.db 52 db backup bak.db
53 file size bak.db 53 file size bak.db
54 } [expr 3*1024] 54 } [expr 3*1024]
55 do_test walbak-1.2 { 55 do_test walbak-1.2 {
56 sqlite3 db2 bak.db 56 sqlite3 db2 bak.db
57 execsql { 57 execsql {
58 SELECT * FROM t1; 58 SELECT * FROM t1;
59 PRAGMA main.journal_mode; 59 PRAGMA main.journal_mode;
60 } db2 60 } db2
61 } {I one wal} 61 } {I one wal}
(...skipping 10 matching lines...) Expand all
72 PRAGMA main.journal_mode; 72 PRAGMA main.journal_mode;
73 } 73 }
74 } {wal} 74 } {wal}
75 do_test walbak-1.5 { 75 do_test walbak-1.5 {
76 list [file size test.db] [file size test.db-wal] 76 list [file size test.db] [file size test.db-wal]
77 } [list 1024 [wal_file_size 6 1024]] 77 } [list 1024 [wal_file_size 6 1024]]
78 do_test walbak-1.6 { 78 do_test walbak-1.6 {
79 execsql { PRAGMA wal_checkpoint } 79 execsql { PRAGMA wal_checkpoint }
80 list [file size test.db] [file size test.db-wal] 80 list [file size test.db] [file size test.db-wal]
81 } [list [expr 3*1024] [wal_file_size 6 1024]] 81 } [list [expr 3*1024] [wal_file_size 6 1024]]
82 do_test walbak-1.6.1 {
83 hexio_read test.db 18 2
84 } {0202}
82 do_test walbak-1.7 { 85 do_test walbak-1.7 {
83 execsql { 86 execsql {
84 CREATE TABLE t2(a, b); 87 CREATE TABLE t2(a, b);
85 INSERT INTO t2 SELECT * FROM t1; 88 INSERT INTO t2 SELECT * FROM t1;
86 DROP TABLE t1; 89 DROP TABLE t1;
87 } 90 }
88 list [file size test.db] [file size test.db-wal] 91 list [file size test.db] [file size test.db-wal]
89 } [list [expr 3*1024] [wal_file_size 6 1024]] 92 } [list [expr 3*1024] [wal_file_size 6 1024]]
90 do_test walbak-1.8 { 93 do_test walbak-1.8 {
91 execsql { VACUUM } 94 execsql { VACUUM }
92 list [file size test.db] [file size test.db-wal] 95 list [file size test.db] [file size test.db-wal]
93 } [list [expr 3*1024] [wal_file_size 8 1024]] 96 } [list [expr 3*1024] [wal_file_size 8 1024]]
94 do_test walbak-1.9 { 97 do_test walbak-1.9 {
95 execsql { PRAGMA wal_checkpoint } 98 execsql { PRAGMA wal_checkpoint }
96 list [file size test.db] [file size test.db-wal] 99 list [file size test.db] [file size test.db-wal]
97 } [list [expr 2*1024] [wal_file_size 8 1024]] 100 } [list [expr 2*1024] [wal_file_size 8 1024]]
98 101
99 #------------------------------------------------------------------------- 102 #-------------------------------------------------------------------------
100 # Backups when the source db is modified mid-backup. 103 # Backups when the source db is modified mid-backup.
101 # 104 #
102 proc sig {{db db}} { 105 proc sig {{db db}} {
103 $db eval { 106 $db eval {
104 PRAGMA integrity_check; 107 PRAGMA integrity_check;
105 SELECT md5sum(a, b) FROM t1; 108 SELECT md5sum(a, b) FROM t1;
106 } 109 }
107 } 110 }
108 db close 111 db close
109 file delete test.db 112 delete_file test.db
110 sqlite3 db test.db 113 sqlite3 db test.db
111 do_test walbak-2.1 { 114 do_test walbak-2.1 {
112 execsql { PRAGMA journal_mode = WAL } 115 execsql { PRAGMA journal_mode = WAL }
113 execsql { 116 execsql {
114 CREATE TABLE t1(a PRIMARY KEY, b); 117 CREATE TABLE t1(a PRIMARY KEY, b);
115 BEGIN; 118 BEGIN;
116 INSERT INTO t1 VALUES(randomblob(500), randomblob(500)); 119 INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
117 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 2 */ 120 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 2 */
118 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 4 */ 121 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 4 */
119 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 8 */ 122 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 8 */
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 sqlite3 db2 test.db2 232 sqlite3 db2 test.db2
230 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL } 233 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL }
231 db2 eval { 234 db2 eval {
232 PRAGMA page_size = 2048; 235 PRAGMA page_size = 2048;
233 PRAGMA journal_mode = PERSIST; 236 PRAGMA journal_mode = PERSIST;
234 CREATE TABLE xx(x); 237 CREATE TABLE xx(x);
235 } 238 }
236 } 239 }
237 240
238 } { 241 } {
239 foreach f [glob -nocomplain test.db*] { file delete -force $f } 242 foreach f [glob -nocomplain test.db*] { forcedelete $f }
240 243
241 eval $setup 244 eval $setup
242 245
243 do_test walbak-3.$tn.1 { 246 do_test walbak-3.$tn.1 {
244 execsql { 247 execsql {
245 CREATE TABLE t1(a, b); 248 CREATE TABLE t1(a, b);
246 INSERT INTO t1 VALUES(1, 2); 249 INSERT INTO t1 VALUES(1, 2);
247 INSERT INTO t1 VALUES(3, 4); 250 INSERT INTO t1 VALUES(3, 4);
248 SELECT * FROM t1; 251 SELECT * FROM t1;
249 } 252 }
(...skipping 14 matching lines...) Expand all
264 } db2 267 } db2
265 } {1 2 3 4 5 6 7 8} 268 } {1 2 3 4 5 6 7 8}
266 269
267 do_test walbak-3.$tn.4 { 270 do_test walbak-3.$tn.4 {
268 sqlite3_backup B db main db2 main 271 sqlite3_backup B db main db2 main
269 B step 10000 272 B step 10000
270 B finish 273 B finish
271 execsql { SELECT * FROM t1 } 274 execsql { SELECT * FROM t1 }
272 } {1 2 3 4 5 6 7 8} 275 } {1 2 3 4 5 6 7 8}
273 276
277 # Check that [db] is still in WAL mode.
278 do_test walbak-3.$tn.5 {
279 execsql { PRAGMA journal_mode }
280 } {wal}
281 do_test walbak-3.$tn.6 {
282 execsql { PRAGMA wal_checkpoint }
283 hexio_read test.db 18 2
284 } {0202}
285
286 # If it was not an in-memory database, check that [db2] is still in
287 # rollback mode.
288 if {[file exists test.db2]} {
289 do_test walbak-3.$tn.7 {
290 execsql { PRAGMA journal_mode } db2
291 } {wal}
292 do_test walbak-3.$tn.8 {
293 execsql { PRAGMA wal_checkpoint }
294 hexio_read test.db 18 2
295 } {0202}
296 }
297
274 db close 298 db close
275 db2 close 299 db2 close
276 } 300 }
277 301
302 #-------------------------------------------------------------------------
303 # Test that the following holds when a backup operation is run:
304 #
305 # Source | Destination inital | Destination final
306 # ---------------------------------------------------
307 # Rollback Rollback Rollback
308 # Rollback WAL WAL
309 # WAL Rollback WAL
310 # WAL WAL WAL
311 #
312 foreach {tn src dest dest_final} {
313 1 delete delete delete
314 2 delete wal wal
315 3 wal delete wal
316 4 wal wal wal
317 } {
318 catch { db close }
319 catch { db2 close }
320 forcedelete test.db test.db2
321
322 do_test walbak-4.$tn.1 {
323 sqlite3 db test.db
324 db eval "PRAGMA journal_mode = $src"
325 db eval {
326 CREATE TABLE t1(a, b);
327 INSERT INTO t1 VALUES('I', 'II');
328 INSERT INTO t1 VALUES('III', 'IV');
329 }
330
331 sqlite3 db2 test.db2
332 db2 eval "PRAGMA journal_mode = $dest"
333 db2 eval {
334 CREATE TABLE t2(x, y);
335 INSERT INTO t2 VALUES('1', '2');
336 INSERT INTO t2 VALUES('3', '4');
337 }
338 } {}
339
340 do_test walbak-4.$tn.2 { execsql { PRAGMA journal_mode } db } $src
341 do_test walbak-4.$tn.3 { execsql { PRAGMA journal_mode } db2 } $dest
342
343 do_test walbak-4.$tn.4 { db backup test.db2 } {}
344 do_test walbak-4.$tn.5 {
345 execsql { SELECT * FROM t1 } db2
346 } {I II III IV}
347 do_test walbak-4.$tn.5 { execsql { PRAGMA journal_mode } db2 } $dest_final
348
349
350 db2 close
351 do_test walbak-4.$tn.6 { file exists test.db2-wal } 0
352 sqlite3 db2 test.db2
353 do_test walbak-4.$tn.7 { execsql { PRAGMA journal_mode } db2 } $dest_final
354 }
355
278 356
279 finish_test 357 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698