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

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

Issue 6990047: Import SQLite 3.7.6.3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/src/test/safety.test ('k') | third_party/sqlite/src/test/savepoint2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2008 December 15 1 # 2008 December 15
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 #***********************************************************************
11 # 11 #
12 # $Id: savepoint.test,v 1.13 2009/07/18 08:30:45 danielk1977 Exp $ 12 # $Id: savepoint.test,v 1.13 2009/07/18 08:30:45 danielk1977 Exp $
13 13
14 set testdir [file dirname $argv0] 14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl 15 source $testdir/tester.tcl
16 16 source $testdir/lock_common.tcl
17 source $testdir/malloc_common.tcl
17 18
18 #---------------------------------------------------------------------- 19 #----------------------------------------------------------------------
19 # The following tests - savepoint-1.* - test that the SAVEPOINT, RELEASE 20 # The following tests - savepoint-1.* - test that the SAVEPOINT, RELEASE
20 # and ROLLBACK TO comands are correctly parsed, and that the auto-commit 21 # and ROLLBACK TO comands are correctly parsed, and that the auto-commit
21 # flag is correctly set and unset as a result. 22 # flag is correctly set and unset as a result.
22 # 23 #
23 do_test savepoint-1.1 { 24 do_test savepoint-1.1 {
25 wal_set_journal_mode
24 execsql { 26 execsql {
25 SAVEPOINT sp1; 27 SAVEPOINT sp1;
26 RELEASE sp1; 28 RELEASE sp1;
27 } 29 }
28 } {} 30 } {}
29 do_test savepoint-1.2 { 31 do_test savepoint-1.2 {
30 execsql { 32 execsql {
31 SAVEPOINT sp1; 33 SAVEPOINT sp1;
32 ROLLBACK TO sp1; 34 ROLLBACK TO sp1;
33 } 35 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } {1} 88 } {1}
87 do_test savepoint-1.5 { 89 do_test savepoint-1.5 {
88 execsql { 90 execsql {
89 SAVEPOINT sp1; 91 SAVEPOINT sp1;
90 ROLLBACK TO sp1; 92 ROLLBACK TO sp1;
91 } 93 }
92 } {} 94 } {}
93 do_test savepoint-1.6 { 95 do_test savepoint-1.6 {
94 execsql COMMIT 96 execsql COMMIT
95 } {} 97 } {}
98 wal_check_journal_mode savepoint-1.7
96 99
97 #------------------------------------------------------------------------ 100 #------------------------------------------------------------------------
98 # These tests - savepoint-2.* - test rollbacks and releases of savepoints 101 # These tests - savepoint-2.* - test rollbacks and releases of savepoints
99 # with a very simple data set. 102 # with a very simple data set.
100 # 103 #
101 104
102 do_test savepoint-2.1 { 105 do_test savepoint-2.1 {
103 execsql { 106 execsql {
104 CREATE TABLE t1(a, b, c); 107 CREATE TABLE t1(a, b, c);
105 BEGIN; 108 BEGIN;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 RELEASE two; 171 RELEASE two;
169 } 172 }
170 execsql { SELECT * FROM t1 } 173 execsql { SELECT * FROM t1 }
171 } {1 2 3 a b c d e f} 174 } {1 2 3 a b c d e f}
172 do_test savepoint-2.11 { 175 do_test savepoint-2.11 {
173 execsql { 176 execsql {
174 ROLLBACK; 177 ROLLBACK;
175 } 178 }
176 execsql { SELECT * FROM t1 } 179 execsql { SELECT * FROM t1 }
177 } {} 180 } {}
181 wal_check_journal_mode savepoint-2.12
178 182
179 #------------------------------------------------------------------------ 183 #------------------------------------------------------------------------
180 # This block of tests - savepoint-3.* - test that when a transaction 184 # This block of tests - savepoint-3.* - test that when a transaction
181 # savepoint is rolled back, locks are not released from database files. 185 # savepoint is rolled back, locks are not released from database files.
182 # And that when a transaction savepoint is released, they are released. 186 # And that when a transaction savepoint is released, they are released.
187 #
188 # These tests do not work in WAL mode. WAL mode does not take RESERVED
189 # locks on the database file.
183 # 190 #
184 do_test savepoint-3.1 { 191 if {[wal_is_wal_mode]==0} {
185 execsql { SAVEPOINT "transaction" } 192 do_test savepoint-3.1 {
186 execsql { PRAGMA lock_status } 193 execsql { SAVEPOINT "transaction" }
187 } {main unlocked temp closed} 194 execsql { PRAGMA lock_status }
188 195 } {main unlocked temp closed}
189 do_test savepoint-3.2 { 196
190 execsql { INSERT INTO t1 VALUES(1, 2, 3) } 197 do_test savepoint-3.2 {
191 execsql { PRAGMA lock_status } 198 execsql { INSERT INTO t1 VALUES(1, 2, 3) }
192 } {main reserved temp closed} 199 execsql { PRAGMA lock_status }
193 200 } {main reserved temp closed}
194 do_test savepoint-3.3 { 201
195 execsql { ROLLBACK TO "transaction" } 202 do_test savepoint-3.3 {
196 execsql { PRAGMA lock_status } 203 execsql { ROLLBACK TO "transaction" }
197 } {main reserved temp closed} 204 execsql { PRAGMA lock_status }
198 205 } {main reserved temp closed}
199 do_test savepoint-3.4 { 206
200 execsql { INSERT INTO t1 VALUES(1, 2, 3) } 207 do_test savepoint-3.4 {
201 execsql { PRAGMA lock_status } 208 execsql { INSERT INTO t1 VALUES(1, 2, 3) }
202 } {main reserved temp closed} 209 execsql { PRAGMA lock_status }
203 210 } {main reserved temp closed}
204 do_test savepoint-3.5 { 211
205 execsql { RELEASE "transaction" } 212 do_test savepoint-3.5 {
206 execsql { PRAGMA lock_status } 213 execsql { RELEASE "transaction" }
207 } {main unlocked temp closed} 214 execsql { PRAGMA lock_status }
215 } {main unlocked temp closed}
216 }
208 217
209 #------------------------------------------------------------------------ 218 #------------------------------------------------------------------------
210 # Test that savepoints that include schema modifications are handled 219 # Test that savepoints that include schema modifications are handled
211 # correctly. Test cases savepoint-4.*. 220 # correctly. Test cases savepoint-4.*.
212 # 221 #
213 do_test savepoint-4.1 { 222 do_test savepoint-4.1 {
214 execsql { 223 execsql {
215 CREATE TABLE t2(d, e, f); 224 CREATE TABLE t2(d, e, f);
216 SELECT sql FROM sqlite_master; 225 SELECT sql FROM sqlite_master;
217 } 226 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 execsql { 266 execsql {
258 ROLLBACK TO sp1; 267 ROLLBACK TO sp1;
259 CREATE TABLE t3(a); 268 CREATE TABLE t3(a);
260 INSERT INTO t3 VALUES('value'); 269 INSERT INTO t3 VALUES('value');
261 } 270 }
262 execsql {SELECT * FROM t3} 271 execsql {SELECT * FROM t3}
263 } {value} 272 } {value}
264 do_test savepoint-4.8 { 273 do_test savepoint-4.8 {
265 execsql COMMIT 274 execsql COMMIT
266 } {} 275 } {}
276 wal_check_journal_mode savepoint-4.9
267 277
268 #------------------------------------------------------------------------ 278 #------------------------------------------------------------------------
269 # Test some logic errors to do with the savepoint feature. 279 # Test some logic errors to do with the savepoint feature.
270 # 280 #
271 281
272 ifcapable incrblob { 282 ifcapable incrblob {
273 do_test savepoint-5.1.1 { 283 do_test savepoint-5.1.1 {
274 execsql { 284 execsql {
275 CREATE TABLE blobs(x); 285 CREATE TABLE blobs(x);
276 INSERT INTO blobs VALUES('a twentyeight character blob'); 286 INSERT INTO blobs VALUES('a twentyeight character blob');
(...skipping 28 matching lines...) Expand all
305 close $fd 315 close $fd
306 execsql {savepoint def} 316 execsql {savepoint def}
307 set fd [db incrblob blobs x 1] 317 set fd [db incrblob blobs x 1]
308 catchsql {release def} 318 catchsql {release def}
309 } {1 {cannot release savepoint - SQL statements in progress}} 319 } {1 {cannot release savepoint - SQL statements in progress}}
310 do_test savepoint-5.3.5 { 320 do_test savepoint-5.3.5 {
311 close $fd 321 close $fd
312 execsql {release abc} 322 execsql {release abc}
313 } {} 323 } {}
314 324
325 # Rollback mode:
326 #
327 # Open a savepoint transaction and insert a row into the database. Then,
328 # using a second database handle, open a read-only transaction on the
329 # database file. Check that the savepoint transaction cannot be committed
330 # until after the read-only transaction has been closed.
331 #
332 # WAL mode:
333 #
334 # As above, except that the savepoint transaction can be successfully
335 # committed before the read-only transaction has been closed.
336 #
315 do_test savepoint-5.4.1 { 337 do_test savepoint-5.4.1 {
316 execsql { 338 execsql {
317 SAVEPOINT main; 339 SAVEPOINT main;
318 INSERT INTO blobs VALUES('another blob'); 340 INSERT INTO blobs VALUES('another blob');
319 } 341 }
320 } {} 342 } {}
321 do_test savepoint-5.4.2 { 343 do_test savepoint-5.4.2 {
322 sqlite3 db2 test.db 344 sqlite3 db2 test.db
323 execsql { BEGIN ; SELECT * FROM blobs } db2 345 execsql { BEGIN ; SELECT count(*) FROM blobs } db2
324 catchsql { RELEASE main } 346 } {1}
325 } {1 {database is locked}} 347 if {[wal_is_wal_mode]} {
326 do_test savepoint-5.4.3 { 348 do_test savepoint-5.4.3 { catchsql "RELEASE main" } {0 {}}
327 db2 close 349 do_test savepoint-5.4.4 { db2 close } {}
328 catchsql { RELEASE main } 350 } else {
329 } {0 {}} 351 do_test savepoint-5.4.3 {
330 do_test savepoint-5.4.4 { 352 catchsql { RELEASE main }
353 } {1 {database is locked}}
354 do_test savepoint-5.4.4 {
355 db2 close
356 catchsql { RELEASE main }
357 } {0 {}}
358 }
359 do_test savepoint-5.4.5 {
331 execsql { SELECT x FROM blobs WHERE rowid = 2 } 360 execsql { SELECT x FROM blobs WHERE rowid = 2 }
332 } {{another blob}} 361 } {{another blob}}
362 do_test savepoint-5.4.6 {
363 execsql { SELECT count(*) FROM blobs }
364 } {2}
333 } 365 }
366 wal_check_journal_mode savepoint-5.5
334 367
335 #------------------------------------------------------------------------- 368 #-------------------------------------------------------------------------
336 # The following tests, savepoint-6.*, test an incr-vacuum inside of a 369 # The following tests, savepoint-6.*, test an incr-vacuum inside of a
337 # couple of nested savepoints. 370 # couple of nested savepoints.
338 # 371 #
339 ifcapable {autovacuum && pragma} { 372 ifcapable {autovacuum && pragma} {
340 db close 373 db close
341 file delete -force test.db 374 file delete -force test.db
342 sqlite3 db test.db 375 sqlite3 db test.db
343 376
344 do_test savepoint-6.1 { 377 do_test savepoint-6.1 {
345 execsql { 378 execsql { PRAGMA auto_vacuum = incremental }
346 PRAGMA auto_vacuum = incremental; 379 wal_set_journal_mode
380 execsql {
347 CREATE TABLE t1(a, b, c); 381 CREATE TABLE t1(a, b, c);
348 CREATE INDEX i1 ON t1(a, b); 382 CREATE INDEX i1 ON t1(a, b);
349 BEGIN; 383 BEGIN;
350 INSERT INTO t1 VALUES(randstr(10,400),randstr(10,400),randstr(10,400)); 384 INSERT INTO t1 VALUES(randstr(10,400),randstr(10,400),randstr(10,400));
351 } 385 }
352 set r "randstr(10,400)" 386 set r "randstr(10,400)"
353 for {set ii 0} {$ii < 10} {incr ii} { 387 for {set ii 0} {$ii < 10} {incr ii} {
354 execsql "INSERT INTO t1 SELECT $r, $r, $r FROM t1" 388 execsql "INSERT INTO t1 SELECT $r, $r, $r FROM t1"
355 } 389 }
356 execsql { COMMIT } 390 execsql { COMMIT }
(...skipping 12 matching lines...) Expand all
369 SAVEPOINT two; 403 SAVEPOINT two;
370 INSERT INTO t1 SELECT randstr(10,400), randstr(10,400), c FROM t1; 404 INSERT INTO t1 SELECT randstr(10,400), randstr(10,400), c FROM t1;
371 DELETE FROM t1 WHERE rowid%2; 405 DELETE FROM t1 WHERE rowid%2;
372 PRAGMA incr_vacuum; 406 PRAGMA incr_vacuum;
373 ROLLBACK TO one; 407 ROLLBACK TO one;
374 COMMIT; 408 COMMIT;
375 } 409 }
376 } {} 410 } {}
377 411
378 integrity_check savepoint-6.4 412 integrity_check savepoint-6.4
413
414 wal_check_journal_mode savepoint-6.5
379 } 415 }
380 416
381 #------------------------------------------------------------------------- 417 #-------------------------------------------------------------------------
382 # The following tests, savepoint-7.*, attempt to break the logic 418 # The following tests, savepoint-7.*, attempt to break the logic
383 # surrounding savepoints by growing and shrinking the database file. 419 # surrounding savepoints by growing and shrinking the database file.
384 # 420 #
385 db close 421 db close
386 file delete -force test.db 422 file delete -force test.db
387 sqlite3 db test.db 423 sqlite3 db test.db
388 424
389 do_test savepoint-7.1 { 425 do_test savepoint-7.1 {
426 execsql { PRAGMA auto_vacuum = incremental }
427 wal_set_journal_mode
390 execsql { 428 execsql {
391 PRAGMA auto_vacuum = incremental;
392 PRAGMA cache_size = 10; 429 PRAGMA cache_size = 10;
393 BEGIN; 430 BEGIN;
394 CREATE TABLE t1(a PRIMARY KEY, b); 431 CREATE TABLE t1(a PRIMARY KEY, b);
395 INSERT INTO t1(a) VALUES('alligator'); 432 INSERT INTO t1(a) VALUES('alligator');
396 INSERT INTO t1(a) VALUES('angelfish'); 433 INSERT INTO t1(a) VALUES('angelfish');
397 INSERT INTO t1(a) VALUES('ant'); 434 INSERT INTO t1(a) VALUES('ant');
398 INSERT INTO t1(a) VALUES('antelope'); 435 INSERT INTO t1(a) VALUES('antelope');
399 INSERT INTO t1(a) VALUES('ape'); 436 INSERT INTO t1(a) VALUES('ape');
400 INSERT INTO t1(a) VALUES('baboon'); 437 INSERT INTO t1(a) VALUES('baboon');
401 INSERT INTO t1(a) VALUES('badger'); 438 INSERT INTO t1(a) VALUES('badger');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 SAVEPOINT one; 479 SAVEPOINT one;
443 DELETE FROM t2; 480 DELETE FROM t2;
444 PRAGMA incremental_vacuum; 481 PRAGMA incremental_vacuum;
445 SAVEPOINT two; 482 SAVEPOINT two;
446 INSERT INTO t2 SELECT a, b FROM t1; 483 INSERT INTO t2 SELECT a, b FROM t1;
447 ROLLBACK TO two; 484 ROLLBACK TO two;
448 COMMIT; 485 COMMIT;
449 } 486 }
450 execsql { PRAGMA integrity_check } 487 execsql { PRAGMA integrity_check }
451 } {ok} 488 } {ok}
489 wal_check_journal_mode savepoint-7.3.3
452 490
453 do_test savepoint-7.4.1 { 491 do_test savepoint-7.4.1 {
454 db close 492 db close
455 file delete -force test.db 493 file delete -force test.db
456 sqlite3 db test.db 494 sqlite3 db test.db
495 execsql { PRAGMA auto_vacuum = incremental }
496 wal_set_journal_mode
457 execsql { 497 execsql {
458 PRAGMA auto_vacuum = incremental;
459 CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); 498 CREATE TABLE t1(a, b, PRIMARY KEY(a, b));
460 INSERT INTO t1 VALUES(randstr(1000,1000), randstr(1000,1000)); 499 INSERT INTO t1 VALUES(randstr(1000,1000), randstr(1000,1000));
461 BEGIN; 500 BEGIN;
462 DELETE FROM t1; 501 DELETE FROM t1;
463 SAVEPOINT one; 502 SAVEPOINT one;
464 PRAGMA incremental_vacuum; 503 PRAGMA incremental_vacuum;
465 ROLLBACK TO one; 504 ROLLBACK TO one;
466 COMMIT; 505 COMMIT;
467 } 506 }
468 507
(...skipping 21 matching lines...) Expand all
490 ROLLBACK TO one; 529 ROLLBACK TO one;
491 COMMIT; 530 COMMIT;
492 PRAGMA integrity_check; 531 PRAGMA integrity_check;
493 } 532 }
494 } {ok} 533 } {ok}
495 do_test savepoint-7.5.2 { 534 do_test savepoint-7.5.2 {
496 execsql { 535 execsql {
497 DROP TABLE t5; 536 DROP TABLE t5;
498 } 537 }
499 } {} 538 } {}
539 wal_check_journal_mode savepoint-7.5.3
500 540
501 # Test oddly named and quoted savepoints. 541 # Test oddly named and quoted savepoints.
502 # 542 #
503 do_test savepoint-8-1 { 543 do_test savepoint-8-1 {
504 execsql { SAVEPOINT "save1" } 544 execsql { SAVEPOINT "save1" }
505 execsql { RELEASE save1 } 545 execsql { RELEASE save1 }
506 } {} 546 } {}
507 do_test savepoint-8-2 { 547 do_test savepoint-8-2 {
508 execsql { SAVEPOINT "Including whitespace " } 548 execsql { SAVEPOINT "Including whitespace " }
509 execsql { RELEASE "including Whitespace " } 549 execsql { RELEASE "including Whitespace " }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 } 631 }
592 } {} 632 } {}
593 633
594 # The lock state of the TEMP database can vary if SQLITE_TEMP_STORE=3 634 # The lock state of the TEMP database can vary if SQLITE_TEMP_STORE=3
595 # And the following set of tests is only really interested in the status 635 # And the following set of tests is only really interested in the status
596 # of the aux1 and aux2 locks. So record the current lock status of 636 # of the aux1 and aux2 locks. So record the current lock status of
597 # TEMP for use in the answers. 637 # TEMP for use in the answers.
598 set templockstate [lindex [db eval {PRAGMA lock_status}] 3] 638 set templockstate [lindex [db eval {PRAGMA lock_status}] 3]
599 639
600 640
601 do_test savepoint-10.2.1 { 641 if {[wal_is_wal_mode]==0} {
602 file delete -force test3.db 642 do_test savepoint-10.2.1 {
603 file delete -force test2.db 643 file delete -force test3.db
604 execsql { 644 file delete -force test2.db
605 ATTACH 'test2.db' AS aux1; 645 execsql {
606 ATTACH 'test3.db' AS aux2; 646 ATTACH 'test2.db' AS aux1;
607 DROP TABLE t1; 647 ATTACH 'test3.db' AS aux2;
608 CREATE TABLE main.t1(x, y); 648 DROP TABLE t1;
609 CREATE TABLE aux1.t2(x, y); 649 CREATE TABLE main.t1(x, y);
610 CREATE TABLE aux2.t3(x, y); 650 CREATE TABLE aux1.t2(x, y);
611 SELECT name FROM sqlite_master 651 CREATE TABLE aux2.t3(x, y);
612 UNION ALL 652 SELECT name FROM sqlite_master
613 SELECT name FROM aux1.sqlite_master 653 UNION ALL
614 UNION ALL 654 SELECT name FROM aux1.sqlite_master
615 SELECT name FROM aux2.sqlite_master; 655 UNION ALL
616 } 656 SELECT name FROM aux2.sqlite_master;
617 } {t1 t2 t3} 657 }
618 do_test savepoint-10.2.2 { 658 } {t1 t2 t3}
619 execsql { PRAGMA lock_status } 659 do_test savepoint-10.2.2 {
620 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] 660 execsql { PRAGMA lock_status }
621 661 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked]
622 do_test savepoint-10.2.3 { 662
623 execsql { 663 do_test savepoint-10.2.3 {
624 SAVEPOINT one; 664 execsql {
625 INSERT INTO t1 VALUES(1, 2); 665 SAVEPOINT one;
626 PRAGMA lock_status; 666 INSERT INTO t1 VALUES(1, 2);
627 } 667 PRAGMA lock_status;
628 } [list main reserved temp $templockstate aux1 unlocked aux2 unlocked] 668 }
629 do_test savepoint-10.2.4 { 669 } [list main reserved temp $templockstate aux1 unlocked aux2 unlocked]
630 execsql { 670 do_test savepoint-10.2.4 {
631 INSERT INTO t3 VALUES(3, 4); 671 execsql {
632 PRAGMA lock_status; 672 INSERT INTO t3 VALUES(3, 4);
633 } 673 PRAGMA lock_status;
634 } [list main reserved temp $templockstate aux1 unlocked aux2 reserved] 674 }
635 do_test savepoint-10.2.5 { 675 } [list main reserved temp $templockstate aux1 unlocked aux2 reserved]
636 execsql { 676 do_test savepoint-10.2.5 {
637 SAVEPOINT two; 677 execsql {
638 INSERT INTO t2 VALUES(5, 6);
639 PRAGMA lock_status;
640 }
641 } [list main reserved temp $templockstate aux1 reserved aux2 reserved]
642 do_test savepoint-10.2.6 {
643 execsql { SELECT * FROM t2 }
644 } {5 6}
645 do_test savepoint-10.2.7 {
646 execsql { ROLLBACK TO two }
647 execsql { SELECT * FROM t2 }
648 } {}
649 do_test savepoint-10.2.8 {
650 execsql { PRAGMA lock_status }
651 } [list main reserved temp $templockstate aux1 reserved aux2 reserved]
652 do_test savepoint-10.2.9 {
653 execsql { SELECT 'a', * FROM t1 UNION ALL SELECT 'b', * FROM t3 }
654 } {a 1 2 b 3 4}
655 do_test savepoint-10.2.9 {
656 execsql {
657 INSERT INTO t2 VALUES(5, 6);
658 RELEASE one;
659 }
660 execsql {
661 SELECT * FROM t1;
662 SELECT * FROM t2;
663 SELECT * FROM t3;
664 }
665 } {1 2 5 6 3 4}
666 do_test savepoint-10.2.9 {
667 execsql { PRAGMA lock_status }
668 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked]
669
670 do_test savepoint-10.2.10 {
671 execsql {
672 SAVEPOINT one;
673 INSERT INTO t1 VALUES('a', 'b');
674 SAVEPOINT two; 678 SAVEPOINT two;
675 INSERT INTO t2 VALUES('c', 'd'); 679 INSERT INTO t2 VALUES(5, 6);
676 SAVEPOINT three; 680 PRAGMA lock_status;
677 INSERT INTO t3 VALUES('e', 'f'); 681 }
678 } 682 } [list main reserved temp $templockstate aux1 reserved aux2 reserved]
679 execsql { 683 do_test savepoint-10.2.6 {
680 SELECT * FROM t1; 684 execsql { SELECT * FROM t2 }
681 SELECT * FROM t2; 685 } {5 6}
682 SELECT * FROM t3; 686 do_test savepoint-10.2.7 {
683 } 687 execsql { ROLLBACK TO two }
684 } {1 2 a b 5 6 c d 3 4 e f} 688 execsql { SELECT * FROM t2 }
685 do_test savepoint-10.2.11 { 689 } {}
686 execsql { ROLLBACK TO two } 690 do_test savepoint-10.2.8 {
687 execsql { 691 execsql { PRAGMA lock_status }
688 SELECT * FROM t1; 692 } [list main reserved temp $templockstate aux1 reserved aux2 reserved]
689 SELECT * FROM t2; 693 do_test savepoint-10.2.9 {
690 SELECT * FROM t3; 694 execsql { SELECT 'a', * FROM t1 UNION ALL SELECT 'b', * FROM t3 }
691 } 695 } {a 1 2 b 3 4}
692 } {1 2 a b 5 6 3 4} 696 do_test savepoint-10.2.9 {
693 do_test savepoint-10.2.12 { 697 execsql {
694 execsql { 698 INSERT INTO t2 VALUES(5, 6);
695 INSERT INTO t3 VALUES('g', 'h'); 699 RELEASE one;
696 ROLLBACK TO two; 700 }
697 } 701 execsql {
698 execsql { 702 SELECT * FROM t1;
699 SELECT * FROM t1; 703 SELECT * FROM t2;
700 SELECT * FROM t2; 704 SELECT * FROM t3;
701 SELECT * FROM t3; 705 }
702 } 706 } {1 2 5 6 3 4}
703 } {1 2 a b 5 6 3 4} 707 do_test savepoint-10.2.9 {
704 do_test savepoint-10.2.13 { 708 execsql { PRAGMA lock_status }
705 execsql { ROLLBACK } 709 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked]
706 execsql { 710
707 SELECT * FROM t1; 711 do_test savepoint-10.2.10 {
708 SELECT * FROM t2; 712 execsql {
709 SELECT * FROM t3; 713 SAVEPOINT one;
710 } 714 INSERT INTO t1 VALUES('a', 'b');
711 } {1 2 5 6 3 4} 715 SAVEPOINT two;
712 do_test savepoint-10.2.14 { 716 INSERT INTO t2 VALUES('c', 'd');
713 execsql { PRAGMA lock_status } 717 SAVEPOINT three;
714 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] 718 INSERT INTO t3 VALUES('e', 'f');
719 }
720 execsql {
721 SELECT * FROM t1;
722 SELECT * FROM t2;
723 SELECT * FROM t3;
724 }
725 } {1 2 a b 5 6 c d 3 4 e f}
726 do_test savepoint-10.2.11 {
727 execsql { ROLLBACK TO two }
728 execsql {
729 SELECT * FROM t1;
730 SELECT * FROM t2;
731 SELECT * FROM t3;
732 }
733 } {1 2 a b 5 6 3 4}
734 do_test savepoint-10.2.12 {
735 execsql {
736 INSERT INTO t3 VALUES('g', 'h');
737 ROLLBACK TO two;
738 }
739 execsql {
740 SELECT * FROM t1;
741 SELECT * FROM t2;
742 SELECT * FROM t3;
743 }
744 } {1 2 a b 5 6 3 4}
745 do_test savepoint-10.2.13 {
746 execsql { ROLLBACK }
747 execsql {
748 SELECT * FROM t1;
749 SELECT * FROM t2;
750 SELECT * FROM t3;
751 }
752 } {1 2 5 6 3 4}
753 do_test savepoint-10.2.14 {
754 execsql { PRAGMA lock_status }
755 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked]
756 }
715 757
716 #------------------------------------------------------------------------- 758 #-------------------------------------------------------------------------
717 # The following tests - savepoint-11.* - test the interaction of 759 # The following tests - savepoint-11.* - test the interaction of
718 # savepoints and creating or dropping tables and indexes in 760 # savepoints and creating or dropping tables and indexes in
719 # auto-vacuum mode. 761 # auto-vacuum mode.
720 # 762 #
721 do_test savepoint-11.1 { 763 do_test savepoint-11.1 {
722 db close 764 db close
723 file delete -force test.db 765 file delete -force test.db
724 sqlite3 db test.db 766 sqlite3 db test.db
767 execsql { PRAGMA auto_vacuum = full; }
768 wal_set_journal_mode
725 execsql { 769 execsql {
726 PRAGMA auto_vacuum = full;
727 CREATE TABLE t1(a, b, UNIQUE(a, b)); 770 CREATE TABLE t1(a, b, UNIQUE(a, b));
728 INSERT INTO t1 VALUES(1, randstr(1000,1000)); 771 INSERT INTO t1 VALUES(1, randstr(1000,1000));
729 INSERT INTO t1 VALUES(2, randstr(1000,1000)); 772 INSERT INTO t1 VALUES(2, randstr(1000,1000));
730 } 773 }
731 } {} 774 } {}
732 do_test savepoint-11.2 { 775 do_test savepoint-11.2 {
733 execsql { 776 execsql {
734 SAVEPOINT one; 777 SAVEPOINT one;
735 CREATE TABLE t2(a, b, UNIQUE(a, b)); 778 CREATE TABLE t2(a, b, UNIQUE(a, b));
736 SAVEPOINT two; 779 SAVEPOINT two;
737 CREATE TABLE t3(a, b, UNIQUE(a, b)); 780 CREATE TABLE t3(a, b, UNIQUE(a, b));
738 } 781 }
739 } {} 782 } {}
740 integrity_check savepoint-11.3 783 integrity_check savepoint-11.3
741 do_test savepoint-11.4 { 784 do_test savepoint-11.4 {
742 execsql { ROLLBACK TO two } 785 execsql { ROLLBACK TO two }
743 } {} 786 } {}
744 integrity_check savepoint-11.5 787 integrity_check savepoint-11.5
745 do_test savepoint-11.6 { 788 do_test savepoint-11.6 {
746 execsql { 789 execsql {
747 CREATE TABLE t3(a, b, UNIQUE(a, b)); 790 CREATE TABLE t3(a, b, UNIQUE(a, b));
748 ROLLBACK TO one; 791 ROLLBACK TO one;
749 } 792 }
750 } {} 793 } {}
751 integrity_check savepoint-11.7 794 integrity_check savepoint-11.7
752 do_test savepoint-11.8 { 795 do_test savepoint-11.8 {
753 execsql { ROLLBACK } 796 execsql { ROLLBACK }
797 execsql { PRAGMA wal_checkpoint }
754 file size test.db 798 file size test.db
755 } {8192} 799 } {8192}
756 800
757
758 do_test savepoint-11.9 { 801 do_test savepoint-11.9 {
759 execsql { 802 execsql {
760 DROP TABLE IF EXISTS t1; 803 DROP TABLE IF EXISTS t1;
761 DROP TABLE IF EXISTS t2; 804 DROP TABLE IF EXISTS t2;
762 DROP TABLE IF EXISTS t3; 805 DROP TABLE IF EXISTS t3;
763 } 806 }
764 } {} 807 } {}
765 do_test savepoint-11.10 { 808 do_test savepoint-11.10 {
766 execsql { 809 execsql {
767 BEGIN; 810 BEGIN;
768 CREATE TABLE t1(a, b); 811 CREATE TABLE t1(a, b);
769 CREATE TABLE t2(x, y); 812 CREATE TABLE t2(x, y);
770 INSERT INTO t2 VALUES(1, 2); 813 INSERT INTO t2 VALUES(1, 2);
771 SAVEPOINT one; 814 SAVEPOINT one;
772 INSERT INTO t2 VALUES(3, 4); 815 INSERT INTO t2 VALUES(3, 4);
773 SAVEPOINT two; 816 SAVEPOINT two;
774 DROP TABLE t1; 817 DROP TABLE t1;
775 ROLLBACK TO two; 818 ROLLBACK TO two;
776 } 819 }
777 execsql {SELECT * FROM t2} 820 execsql {SELECT * FROM t2}
778 } {1 2 3 4} 821 } {1 2 3 4}
779 do_test savepoint-11.11 { 822 do_test savepoint-11.11 {
780 execsql COMMIT 823 execsql COMMIT
781 } {} 824 } {}
782 do_test savepoint-11.12 { 825 do_test savepoint-11.12 {
783 execsql {SELECT * FROM t2} 826 execsql {SELECT * FROM t2}
784 } {1 2 3 4} 827 } {1 2 3 4}
828 wal_check_journal_mode savepoint-11.13
785 829
786 #------------------------------------------------------------------------- 830 #-------------------------------------------------------------------------
787 # The following tests - savepoint-12.* - test the interaction of 831 # The following tests - savepoint-12.* - test the interaction of
788 # savepoints and "ON CONFLICT ROLLBACK" clauses. 832 # savepoints and "ON CONFLICT ROLLBACK" clauses.
789 # 833 #
790 do_test savepoint-12.1 { 834 do_test savepoint-12.1 {
791 execsql { 835 execsql {
792 CREATE TABLE t4(a PRIMARY KEY, b); 836 CREATE TABLE t4(a PRIMARY KEY, b);
793 INSERT INTO t4 VALUES(1, 'one'); 837 INSERT INTO t4 VALUES(1, 'one');
794 } 838 }
(...skipping 13 matching lines...) Expand all
808 SAVEPOINT sp2; 852 SAVEPOINT sp2;
809 INSERT OR ROLLBACK INTO t4 VALUES(1, 'one'); 853 INSERT OR ROLLBACK INTO t4 VALUES(1, 'one');
810 } 854 }
811 } {1 {column a is not unique}} 855 } {1 {column a is not unique}}
812 do_test savepoint-12.3 { 856 do_test savepoint-12.3 {
813 sqlite3_get_autocommit db 857 sqlite3_get_autocommit db
814 } {1} 858 } {1}
815 do_test savepoint-12.4 { 859 do_test savepoint-12.4 {
816 execsql { SAVEPOINT one } 860 execsql { SAVEPOINT one }
817 } {} 861 } {}
862 wal_check_journal_mode savepoint-12.5
818 863
819 #------------------------------------------------------------------------- 864 #-------------------------------------------------------------------------
820 # The following tests - savepoint-13.* - test the interaction of 865 # The following tests - savepoint-13.* - test the interaction of
821 # savepoints and "journal_mode = off". 866 # savepoints and "journal_mode = off".
822 # 867 #
823 do_test savepoint-13.1 { 868 if {[wal_is_wal_mode]==0} {
824 db close 869 do_test savepoint-13.1 {
825 catch {file delete -force test.db} 870 db close
826 sqlite3 db test.db 871 catch {file delete -force test.db}
827 execsql { 872 sqlite3 db test.db
828 BEGIN; 873 execsql {
829 CREATE TABLE t1(a PRIMARY KEY, b); 874 BEGIN;
830 INSERT INTO t1 VALUES(1, 2); 875 CREATE TABLE t1(a PRIMARY KEY, b);
831 COMMIT; 876 INSERT INTO t1 VALUES(1, 2);
832 PRAGMA journal_mode = off; 877 COMMIT;
833 } 878 PRAGMA journal_mode = off;
834 } {off} 879 }
835 do_test savepoint-13.2 { 880 } {off}
836 execsql { 881 do_test savepoint-13.2 {
837 BEGIN; 882 execsql {
838 INSERT INTO t1 VALUES(3, 4); 883 BEGIN;
839 INSERT INTO t1 SELECT a+4,b+4 FROM t1; 884 INSERT INTO t1 VALUES(3, 4);
840 COMMIT; 885 INSERT INTO t1 SELECT a+4,b+4 FROM t1;
841 } 886 COMMIT;
887 }
888 } {}
889 do_test savepoint-13.3 {
890 execsql {
891 BEGIN;
892 INSERT INTO t1 VALUES(9, 10);
893 SAVEPOINT s1;
894 INSERT INTO t1 VALUES(11, 12);
895 COMMIT;
896 }
897 } {}
898 do_test savepoint-13.4 {
899 execsql {
900 BEGIN;
901 INSERT INTO t1 VALUES(13, 14);
902 SAVEPOINT s1;
903 INSERT INTO t1 VALUES(15, 16);
904 ROLLBACK TO s1;
905 ROLLBACK;
906 SELECT * FROM t1;
907 }
908 } {1 2 3 4 5 6 7 8 9 10 11 12}
909 }
910
911 db close
912 file delete test.db
913 do_multiclient_test tn {
914 do_test savepoint-14.$tn.1 {
915 sql1 {
916 CREATE TABLE foo(x);
917 INSERT INTO foo VALUES(1);
918 INSERT INTO foo VALUES(2);
919 }
920 sql2 {
921 BEGIN;
922 SELECT * FROM foo;
923 }
924 } {1 2}
925 do_test savepoint-14.$tn.2 {
926 sql1 {
927 SAVEPOINT one;
928 INSERT INTO foo VALUES(1);
929 }
930 csql1 { RELEASE one }
931 } {1 {database is locked}}
932 do_test savepoint-14.$tn.3 {
933 sql1 { ROLLBACK TO one }
934 sql2 { COMMIT }
935 sql1 { RELEASE one }
936 } {}
937
938 do_test savepoint-14.$tn.4 {
939 sql2 {
940 BEGIN;
941 SELECT * FROM foo;
942 }
943 } {1 2}
944 do_test savepoint-14.$tn.5 {
945 sql1 {
946 SAVEPOINT one;
947 INSERT INTO foo VALUES(1);
948 }
949 csql1 { RELEASE one }
950 } {1 {database is locked}}
951 do_test savepoint-14.$tn.6 {
952 sql2 { COMMIT }
953 sql1 {
954 ROLLBACK TO one;
955 INSERT INTO foo VALUES(3);
956 INSERT INTO foo VALUES(4);
957 INSERT INTO foo VALUES(5);
958 RELEASE one;
959 }
960 } {}
961 do_test savepoint-14.$tn.7 {
962 sql2 { CREATE INDEX fooidx ON foo(x); }
963 sql3 { PRAGMA integrity_check }
964 } {ok}
965 }
966
967 do_multiclient_test tn {
968 do_test savepoint-15.$tn.1 {
969 sql1 {
970 CREATE TABLE foo(x);
971 INSERT INTO foo VALUES(1);
972 INSERT INTO foo VALUES(2);
973 }
974 sql2 { BEGIN; SELECT * FROM foo; }
975 } {1 2}
976 do_test savepoint-15.$tn.2 {
977 sql1 {
978 PRAGMA locking_mode = EXCLUSIVE;
979 BEGIN;
980 INSERT INTO foo VALUES(3);
981 }
982 csql1 { COMMIT }
983 } {1 {database is locked}}
984 do_test savepoint-15.$tn.3 {
985 sql1 { ROLLBACK }
986 sql2 { COMMIT }
987 sql1 {
988 INSERT INTO foo VALUES(3);
989 PRAGMA locking_mode = NORMAL;
990 INSERT INTO foo VALUES(4);
991 }
992 sql2 { CREATE INDEX fooidx ON foo(x); }
993 sql3 { PRAGMA integrity_check }
994 } {ok}
995 }
996
997 do_multiclient_test tn {
998 do_test savepoint-16.$tn.1 {
999 sql1 {
1000 CREATE TABLE foo(x);
1001 INSERT INTO foo VALUES(1);
1002 INSERT INTO foo VALUES(2);
1003 }
1004 } {}
1005 do_test savepoint-16.$tn.2 {
1006
1007 db eval {SELECT * FROM foo} {
1008 sql1 { INSERT INTO foo VALUES(3) }
1009 sql2 { SELECT * FROM foo }
1010 sql1 { INSERT INTO foo VALUES(4) }
1011 break
1012 }
1013
1014 sql2 { CREATE INDEX fooidx ON foo(x); }
1015 sql3 { PRAGMA integrity_check }
1016 } {ok}
1017 do_test savepoint-16.$tn.3 {
1018 sql1 { SELECT * FROM foo }
1019 } {1 2 3 4}
1020 }
1021
1022 #-------------------------------------------------------------------------
1023 # This next block of tests verifies that a problem reported on the mailing
1024 # list has been resolved. At one point the second "CREATE TABLE t6" would
1025 # fail as table t6 still existed in the internal cache of the db schema
1026 # (even though it had been removed from the database by the ROLLBACK
1027 # command).
1028 #
1029 sqlite3 db test.db
1030 do_execsql_test savepoint-17.1 {
1031 BEGIN;
1032 CREATE TABLE t6(a, b);
1033 INSERT INTO t6 VALUES(1, 2);
1034 SAVEPOINT one;
1035 INSERT INTO t6 VALUES(3, 4);
1036 ROLLBACK TO one;
1037 SELECT * FROM t6;
1038 ROLLBACK;
1039 } {1 2}
1040
1041 do_execsql_test savepoint-17.2 {
1042 CREATE TABLE t6(a, b);
842 } {} 1043 } {}
843 do_test savepoint-13.3 {
844 execsql {
845 BEGIN;
846 INSERT INTO t1 VALUES(9, 10);
847 SAVEPOINT s1;
848 INSERT INTO t1 VALUES(11, 12);
849 COMMIT;
850 }
851 } {}
852 do_test savepoint-13.4 {
853 execsql {
854 BEGIN;
855 INSERT INTO t1 VALUES(13, 14);
856 SAVEPOINT s1;
857 INSERT INTO t1 VALUES(15, 16);
858 ROLLBACK TO s1;
859 ROLLBACK;
860 SELECT * FROM t1;
861 }
862 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
863 1044
864 finish_test 1045 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/safety.test ('k') | third_party/sqlite/src/test/savepoint2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698