OLD | NEW |
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 #*********************************************************************** |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 do_test savepoint-5.2 { | 297 do_test savepoint-5.2 { |
298 execsql {RELEASE abc} | 298 execsql {RELEASE abc} |
299 catchsql {RELEASE abc} | 299 catchsql {RELEASE abc} |
300 } {1 {no such savepoint: abc}} | 300 } {1 {no such savepoint: abc}} |
301 | 301 |
302 do_test savepoint-5.3.1 { | 302 do_test savepoint-5.3.1 { |
303 execsql {SAVEPOINT abc} | 303 execsql {SAVEPOINT abc} |
304 catchsql {ROLLBACK TO def} | 304 catchsql {ROLLBACK TO def} |
305 } {1 {no such savepoint: def}} | 305 } {1 {no such savepoint: def}} |
306 do_test savepoint-5.3.2 { | 306 do_test savepoint-5.3.2.1 { |
307 execsql {SAVEPOINT def} | 307 execsql {SAVEPOINT def} |
308 set fd [db incrblob -readonly blobs x 1] | 308 set fd [db incrblob -readonly blobs x 1] |
| 309 set rc [catch {seek $fd 0;read $fd} res] |
| 310 lappend rc $res |
| 311 } {0 {hellontyeight character blob}} |
| 312 do_test savepoint-5.3.2.2 { |
309 catchsql {ROLLBACK TO def} | 313 catchsql {ROLLBACK TO def} |
310 } {1 {cannot rollback savepoint - SQL statements in progress}} | 314 } {0 {}} |
| 315 do_test savepoint-5.3.2.3 { |
| 316 set rc [catch {seek $fd 0; read $fd} res] |
| 317 set rc |
| 318 } {0} |
311 do_test savepoint-5.3.3 { | 319 do_test savepoint-5.3.3 { |
312 catchsql {RELEASE def} | 320 catchsql {RELEASE def} |
313 } {0 {}} | 321 } {0 {}} |
314 do_test savepoint-5.3.4 { | 322 do_test savepoint-5.3.4 { |
315 close $fd | 323 close $fd |
316 execsql {savepoint def} | 324 execsql {savepoint def} |
317 set fd [db incrblob blobs x 1] | 325 set fd [db incrblob blobs x 1] |
318 catchsql {release def} | 326 catchsql {release def} |
319 } {1 {cannot release savepoint - SQL statements in progress}} | 327 } {1 {cannot release savepoint - SQL statements in progress}} |
320 do_test savepoint-5.3.5 { | 328 do_test savepoint-5.3.5 { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } {2} | 372 } {2} |
365 } | 373 } |
366 wal_check_journal_mode savepoint-5.5 | 374 wal_check_journal_mode savepoint-5.5 |
367 | 375 |
368 #------------------------------------------------------------------------- | 376 #------------------------------------------------------------------------- |
369 # The following tests, savepoint-6.*, test an incr-vacuum inside of a | 377 # The following tests, savepoint-6.*, test an incr-vacuum inside of a |
370 # couple of nested savepoints. | 378 # couple of nested savepoints. |
371 # | 379 # |
372 ifcapable {autovacuum && pragma} { | 380 ifcapable {autovacuum && pragma} { |
373 db close | 381 db close |
374 file delete -force test.db | 382 forcedelete test.db |
375 sqlite3 db test.db | 383 sqlite3 db test.db |
376 | 384 |
377 do_test savepoint-6.1 { | 385 do_test savepoint-6.1 { |
378 execsql { PRAGMA auto_vacuum = incremental } | 386 execsql { PRAGMA auto_vacuum = incremental } |
379 wal_set_journal_mode | 387 wal_set_journal_mode |
380 execsql { | 388 execsql { |
381 CREATE TABLE t1(a, b, c); | 389 CREATE TABLE t1(a, b, c); |
382 CREATE INDEX i1 ON t1(a, b); | 390 CREATE INDEX i1 ON t1(a, b); |
383 BEGIN; | 391 BEGIN; |
384 INSERT INTO t1 VALUES(randstr(10,400),randstr(10,400),randstr(10,400)); | 392 INSERT INTO t1 VALUES(randstr(10,400),randstr(10,400),randstr(10,400)); |
(...skipping 27 matching lines...) Expand all Loading... |
412 integrity_check savepoint-6.4 | 420 integrity_check savepoint-6.4 |
413 | 421 |
414 wal_check_journal_mode savepoint-6.5 | 422 wal_check_journal_mode savepoint-6.5 |
415 } | 423 } |
416 | 424 |
417 #------------------------------------------------------------------------- | 425 #------------------------------------------------------------------------- |
418 # The following tests, savepoint-7.*, attempt to break the logic | 426 # The following tests, savepoint-7.*, attempt to break the logic |
419 # surrounding savepoints by growing and shrinking the database file. | 427 # surrounding savepoints by growing and shrinking the database file. |
420 # | 428 # |
421 db close | 429 db close |
422 file delete -force test.db | 430 forcedelete test.db |
423 sqlite3 db test.db | 431 sqlite3 db test.db |
424 | 432 |
425 do_test savepoint-7.1 { | 433 do_test savepoint-7.1 { |
426 execsql { PRAGMA auto_vacuum = incremental } | 434 execsql { PRAGMA auto_vacuum = incremental } |
427 wal_set_journal_mode | 435 wal_set_journal_mode |
428 execsql { | 436 execsql { |
429 PRAGMA cache_size = 10; | 437 PRAGMA cache_size = 10; |
430 BEGIN; | 438 BEGIN; |
431 CREATE TABLE t1(a PRIMARY KEY, b); | 439 CREATE TABLE t1(a PRIMARY KEY, b); |
432 INSERT INTO t1(a) VALUES('alligator'); | 440 INSERT INTO t1(a) VALUES('alligator'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 INSERT INTO t2 SELECT a, b FROM t1; | 491 INSERT INTO t2 SELECT a, b FROM t1; |
484 ROLLBACK TO two; | 492 ROLLBACK TO two; |
485 COMMIT; | 493 COMMIT; |
486 } | 494 } |
487 execsql { PRAGMA integrity_check } | 495 execsql { PRAGMA integrity_check } |
488 } {ok} | 496 } {ok} |
489 wal_check_journal_mode savepoint-7.3.3 | 497 wal_check_journal_mode savepoint-7.3.3 |
490 | 498 |
491 do_test savepoint-7.4.1 { | 499 do_test savepoint-7.4.1 { |
492 db close | 500 db close |
493 file delete -force test.db | 501 forcedelete test.db |
494 sqlite3 db test.db | 502 sqlite3 db test.db |
495 execsql { PRAGMA auto_vacuum = incremental } | 503 execsql { PRAGMA auto_vacuum = incremental } |
496 wal_set_journal_mode | 504 wal_set_journal_mode |
497 execsql { | 505 execsql { |
498 CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); | 506 CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); |
499 INSERT INTO t1 VALUES(randstr(1000,1000), randstr(1000,1000)); | 507 INSERT INTO t1 VALUES(randstr(1000,1000), randstr(1000,1000)); |
500 BEGIN; | 508 BEGIN; |
501 DELETE FROM t1; | 509 DELETE FROM t1; |
502 SAVEPOINT one; | 510 SAVEPOINT one; |
503 PRAGMA incremental_vacuum; | 511 PRAGMA incremental_vacuum; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 } {} | 554 } {} |
547 do_test savepoint-8-2 { | 555 do_test savepoint-8-2 { |
548 execsql { SAVEPOINT "Including whitespace " } | 556 execsql { SAVEPOINT "Including whitespace " } |
549 execsql { RELEASE "including Whitespace " } | 557 execsql { RELEASE "including Whitespace " } |
550 } {} | 558 } {} |
551 | 559 |
552 # Test that the authorization callback works. | 560 # Test that the authorization callback works. |
553 # | 561 # |
554 ifcapable auth { | 562 ifcapable auth { |
555 proc auth {args} { | 563 proc auth {args} { |
556 eval lappend ::authdata $args | 564 eval lappend ::authdata [lrange $args 0 4] |
557 return SQLITE_OK | 565 return SQLITE_OK |
558 } | 566 } |
559 db auth auth | 567 db auth auth |
560 | 568 |
561 do_test savepoint-9.1 { | 569 do_test savepoint-9.1 { |
562 set ::authdata [list] | 570 set ::authdata [list] |
563 execsql { SAVEPOINT sp1 } | 571 execsql { SAVEPOINT sp1 } |
564 set ::authdata | 572 set ::authdata |
565 } {SQLITE_SAVEPOINT BEGIN sp1 {} {}} | 573 } {SQLITE_SAVEPOINT BEGIN sp1 {} {}} |
566 do_test savepoint-9.2 { | 574 do_test savepoint-9.2 { |
567 set ::authdata [list] | 575 set ::authdata [list] |
568 execsql { ROLLBACK TO sp1 } | 576 execsql { ROLLBACK TO sp1 } |
569 set ::authdata | 577 set ::authdata |
570 } {SQLITE_SAVEPOINT ROLLBACK sp1 {} {}} | 578 } {SQLITE_SAVEPOINT ROLLBACK sp1 {} {}} |
571 do_test savepoint-9.3 { | 579 do_test savepoint-9.3 { |
572 set ::authdata [list] | 580 set ::authdata [list] |
573 execsql { RELEASE sp1 } | 581 execsql { RELEASE sp1 } |
574 set ::authdata | 582 set ::authdata |
575 } {SQLITE_SAVEPOINT RELEASE sp1 {} {}} | 583 } {SQLITE_SAVEPOINT RELEASE sp1 {} {}} |
576 | 584 |
577 proc auth {args} { | 585 proc auth {args} { |
578 eval lappend ::authdata $args | 586 eval lappend ::authdata [lrange $args 0 4] |
579 return SQLITE_DENY | 587 return SQLITE_DENY |
580 } | 588 } |
581 db auth auth | 589 db auth auth |
582 | 590 |
583 do_test savepoint-9.4 { | 591 do_test savepoint-9.4 { |
584 set ::authdata [list] | 592 set ::authdata [list] |
585 set res [catchsql { SAVEPOINT sp1 }] | 593 set res [catchsql { SAVEPOINT sp1 }] |
586 concat $::authdata $res | 594 concat $::authdata $res |
587 } {SQLITE_SAVEPOINT BEGIN sp1 {} {} 1 {not authorized}} | 595 } {SQLITE_SAVEPOINT BEGIN sp1 {} {} 1 {not authorized}} |
588 do_test savepoint-9.5 { | 596 do_test savepoint-9.5 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 641 |
634 # The lock state of the TEMP database can vary if SQLITE_TEMP_STORE=3 | 642 # The lock state of the TEMP database can vary if SQLITE_TEMP_STORE=3 |
635 # And the following set of tests is only really interested in the status | 643 # And the following set of tests is only really interested in the status |
636 # of the aux1 and aux2 locks. So record the current lock status of | 644 # of the aux1 and aux2 locks. So record the current lock status of |
637 # TEMP for use in the answers. | 645 # TEMP for use in the answers. |
638 set templockstate [lindex [db eval {PRAGMA lock_status}] 3] | 646 set templockstate [lindex [db eval {PRAGMA lock_status}] 3] |
639 | 647 |
640 | 648 |
641 if {[wal_is_wal_mode]==0} { | 649 if {[wal_is_wal_mode]==0} { |
642 do_test savepoint-10.2.1 { | 650 do_test savepoint-10.2.1 { |
643 file delete -force test3.db | 651 forcedelete test3.db |
644 file delete -force test2.db | 652 forcedelete test2.db |
645 execsql { | 653 execsql { |
646 ATTACH 'test2.db' AS aux1; | 654 ATTACH 'test2.db' AS aux1; |
647 ATTACH 'test3.db' AS aux2; | 655 ATTACH 'test3.db' AS aux2; |
648 DROP TABLE t1; | 656 DROP TABLE t1; |
649 CREATE TABLE main.t1(x, y); | 657 CREATE TABLE main.t1(x, y); |
650 CREATE TABLE aux1.t2(x, y); | 658 CREATE TABLE aux1.t2(x, y); |
651 CREATE TABLE aux2.t3(x, y); | 659 CREATE TABLE aux2.t3(x, y); |
652 SELECT name FROM sqlite_master | 660 SELECT name FROM sqlite_master; |
653 UNION ALL | 661 SELECT name FROM aux1.sqlite_master; |
654 SELECT name FROM aux1.sqlite_master | |
655 UNION ALL | |
656 SELECT name FROM aux2.sqlite_master; | 662 SELECT name FROM aux2.sqlite_master; |
657 } | 663 } |
658 } {t1 t2 t3} | 664 } {t1 t2 t3} |
659 do_test savepoint-10.2.2 { | 665 do_test savepoint-10.2.2 { |
660 execsql { PRAGMA lock_status } | 666 execsql { PRAGMA lock_status } |
661 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] | 667 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] |
662 | 668 |
663 do_test savepoint-10.2.3 { | 669 do_test savepoint-10.2.3 { |
664 execsql { | 670 execsql { |
665 SAVEPOINT one; | 671 SAVEPOINT one; |
(...skipping 18 matching lines...) Expand all Loading... |
684 execsql { SELECT * FROM t2 } | 690 execsql { SELECT * FROM t2 } |
685 } {5 6} | 691 } {5 6} |
686 do_test savepoint-10.2.7 { | 692 do_test savepoint-10.2.7 { |
687 execsql { ROLLBACK TO two } | 693 execsql { ROLLBACK TO two } |
688 execsql { SELECT * FROM t2 } | 694 execsql { SELECT * FROM t2 } |
689 } {} | 695 } {} |
690 do_test savepoint-10.2.8 { | 696 do_test savepoint-10.2.8 { |
691 execsql { PRAGMA lock_status } | 697 execsql { PRAGMA lock_status } |
692 } [list main reserved temp $templockstate aux1 reserved aux2 reserved] | 698 } [list main reserved temp $templockstate aux1 reserved aux2 reserved] |
693 do_test savepoint-10.2.9 { | 699 do_test savepoint-10.2.9 { |
694 execsql { SELECT 'a', * FROM t1 UNION ALL SELECT 'b', * FROM t3 } | 700 execsql { SELECT 'a', * FROM t1 ; SELECT 'b', * FROM t3 } |
695 } {a 1 2 b 3 4} | 701 } {a 1 2 b 3 4} |
696 do_test savepoint-10.2.9 { | 702 do_test savepoint-10.2.9 { |
697 execsql { | 703 execsql { |
698 INSERT INTO t2 VALUES(5, 6); | 704 INSERT INTO t2 VALUES(5, 6); |
699 RELEASE one; | 705 RELEASE one; |
700 } | 706 } |
701 execsql { | 707 execsql { |
702 SELECT * FROM t1; | 708 SELECT * FROM t1; |
703 SELECT * FROM t2; | 709 SELECT * FROM t2; |
704 SELECT * FROM t3; | 710 SELECT * FROM t3; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] | 761 } [list main unlocked temp $templockstate aux1 unlocked aux2 unlocked] |
756 } | 762 } |
757 | 763 |
758 #------------------------------------------------------------------------- | 764 #------------------------------------------------------------------------- |
759 # The following tests - savepoint-11.* - test the interaction of | 765 # The following tests - savepoint-11.* - test the interaction of |
760 # savepoints and creating or dropping tables and indexes in | 766 # savepoints and creating or dropping tables and indexes in |
761 # auto-vacuum mode. | 767 # auto-vacuum mode. |
762 # | 768 # |
763 do_test savepoint-11.1 { | 769 do_test savepoint-11.1 { |
764 db close | 770 db close |
765 file delete -force test.db | 771 forcedelete test.db |
766 sqlite3 db test.db | 772 sqlite3 db test.db |
767 execsql { PRAGMA auto_vacuum = full; } | 773 execsql { PRAGMA auto_vacuum = full; } |
768 wal_set_journal_mode | 774 wal_set_journal_mode |
769 execsql { | 775 execsql { |
770 CREATE TABLE t1(a, b, UNIQUE(a, b)); | 776 CREATE TABLE t1(a, b, UNIQUE(a, b)); |
771 INSERT INTO t1 VALUES(1, randstr(1000,1000)); | 777 INSERT INTO t1 VALUES(1, randstr(1000,1000)); |
772 INSERT INTO t1 VALUES(2, randstr(1000,1000)); | 778 INSERT INTO t1 VALUES(2, randstr(1000,1000)); |
773 } | 779 } |
774 } {} | 780 } {} |
775 do_test savepoint-11.2 { | 781 do_test savepoint-11.2 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 # later on. | 851 # later on. |
846 # | 852 # |
847 catchsql { | 853 catchsql { |
848 BEGIN; | 854 BEGIN; |
849 INSERT INTO t4 VALUES(2, 'two'); | 855 INSERT INTO t4 VALUES(2, 'two'); |
850 SAVEPOINT sp1; | 856 SAVEPOINT sp1; |
851 INSERT INTO t4 VALUES(3, 'three'); | 857 INSERT INTO t4 VALUES(3, 'three'); |
852 SAVEPOINT sp2; | 858 SAVEPOINT sp2; |
853 INSERT OR ROLLBACK INTO t4 VALUES(1, 'one'); | 859 INSERT OR ROLLBACK INTO t4 VALUES(1, 'one'); |
854 } | 860 } |
855 } {1 {column a is not unique}} | 861 } {1 {UNIQUE constraint failed: t4.a}} |
856 do_test savepoint-12.3 { | 862 do_test savepoint-12.3 { |
857 sqlite3_get_autocommit db | 863 sqlite3_get_autocommit db |
858 } {1} | 864 } {1} |
859 do_test savepoint-12.4 { | 865 do_test savepoint-12.4 { |
860 execsql { SAVEPOINT one } | 866 execsql { SAVEPOINT one } |
861 } {} | 867 } {} |
862 wal_check_journal_mode savepoint-12.5 | 868 wal_check_journal_mode savepoint-12.5 |
863 | 869 |
864 #------------------------------------------------------------------------- | 870 #------------------------------------------------------------------------- |
865 # The following tests - savepoint-13.* - test the interaction of | 871 # The following tests - savepoint-13.* - test the interaction of |
866 # savepoints and "journal_mode = off". | 872 # savepoints and "journal_mode = off". |
867 # | 873 # |
868 if {[wal_is_wal_mode]==0} { | 874 if {[wal_is_wal_mode]==0} { |
869 do_test savepoint-13.1 { | 875 do_test savepoint-13.1 { |
870 db close | 876 db close |
871 catch {file delete -force test.db} | 877 catch {forcedelete test.db} |
872 sqlite3 db test.db | 878 sqlite3 db test.db |
873 execsql { | 879 execsql { |
874 BEGIN; | 880 BEGIN; |
875 CREATE TABLE t1(a PRIMARY KEY, b); | 881 CREATE TABLE t1(a PRIMARY KEY, b); |
876 INSERT INTO t1 VALUES(1, 2); | 882 INSERT INTO t1 VALUES(1, 2); |
877 COMMIT; | 883 COMMIT; |
878 PRAGMA journal_mode = off; | 884 PRAGMA journal_mode = off; |
879 } | 885 } |
880 } {off} | 886 } {off} |
881 do_test savepoint-13.2 { | 887 do_test savepoint-13.2 { |
(...skipping 20 matching lines...) Expand all Loading... |
902 SAVEPOINT s1; | 908 SAVEPOINT s1; |
903 INSERT INTO t1 VALUES(15, 16); | 909 INSERT INTO t1 VALUES(15, 16); |
904 ROLLBACK TO s1; | 910 ROLLBACK TO s1; |
905 ROLLBACK; | 911 ROLLBACK; |
906 SELECT * FROM t1; | 912 SELECT * FROM t1; |
907 } | 913 } |
908 } {1 2 3 4 5 6 7 8 9 10 11 12} | 914 } {1 2 3 4 5 6 7 8 9 10 11 12} |
909 } | 915 } |
910 | 916 |
911 db close | 917 db close |
912 file delete test.db | 918 delete_file test.db |
913 do_multiclient_test tn { | 919 do_multiclient_test tn { |
914 do_test savepoint-14.$tn.1 { | 920 do_test savepoint-14.$tn.1 { |
915 sql1 { | 921 sql1 { |
916 CREATE TABLE foo(x); | 922 CREATE TABLE foo(x); |
917 INSERT INTO foo VALUES(1); | 923 INSERT INTO foo VALUES(1); |
918 INSERT INTO foo VALUES(2); | 924 INSERT INTO foo VALUES(2); |
919 } | 925 } |
920 sql2 { | 926 sql2 { |
921 BEGIN; | 927 BEGIN; |
922 SELECT * FROM foo; | 928 SELECT * FROM foo; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 ROLLBACK TO one; | 1042 ROLLBACK TO one; |
1037 SELECT * FROM t6; | 1043 SELECT * FROM t6; |
1038 ROLLBACK; | 1044 ROLLBACK; |
1039 } {1 2} | 1045 } {1 2} |
1040 | 1046 |
1041 do_execsql_test savepoint-17.2 { | 1047 do_execsql_test savepoint-17.2 { |
1042 CREATE TABLE t6(a, b); | 1048 CREATE TABLE t6(a, b); |
1043 } {} | 1049 } {} |
1044 | 1050 |
1045 finish_test | 1051 finish_test |
OLD | NEW |