|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source [file join [file dirname [info script]] rbu_common.tcl] |
|
|
if_no_rbu_support { finish_test ; return } |
|
|
set ::testprefix rbu11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_test 1.1 { |
|
|
sqlite3rbu_create_vfs -default rbu "" |
|
|
reset_db |
|
|
catchsql { PRAGMA temp_store_directory = '/no/such/directory' } |
|
|
} {1 {not a writable directory}} |
|
|
|
|
|
do_test 1.2 { |
|
|
catchsql " PRAGMA temp_store_directory = '[pwd]' " |
|
|
} {0 {}} |
|
|
|
|
|
do_test 1.3 { |
|
|
catchsql " PRAGMA temp_store_directory = '' " |
|
|
} {0 {}} |
|
|
|
|
|
do_test 1.4 { |
|
|
db close |
|
|
sqlite3rbu_destroy_vfs rbu |
|
|
} {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_db |
|
|
do_execsql_test 2.1 { |
|
|
CREATE TABLE t1(a PRIMARY KEY, b, c); |
|
|
INSERT INTO t1 VALUES(1, 2, 3); |
|
|
PRAGMA journal_mode = 'wal'; |
|
|
CREATE TABLE t2(d PRIMARY KEY, e, f); |
|
|
} {wal} |
|
|
|
|
|
do_test 2.2 { |
|
|
db_save |
|
|
db close |
|
|
|
|
|
forcedelete rbu.db |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { |
|
|
CREATE TABLE data_t1(a, b, c, rbu_control); |
|
|
INSERT INTO data_t1 VALUES(4, 5, 6, 0); |
|
|
INSERT INTO data_t1 VALUES(7, 8, 9, 0); |
|
|
} |
|
|
dbo close |
|
|
|
|
|
db_restore |
|
|
hexio_write test.db 18 0101 |
|
|
file exists test.db-wal |
|
|
} {1} |
|
|
|
|
|
do_test 2.3 { |
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
} {SQLITE_ERROR} |
|
|
|
|
|
do_test 2.4 { |
|
|
list [catch {rbu close} msg] $msg |
|
|
} {1 {SQLITE_ERROR - cannot update wal mode database}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_db |
|
|
do_execsql_test 3.1 { |
|
|
CREATE TABLE "(t1)"(a PRIMARY KEY, b, c); |
|
|
INSERT INTO "(t1)" VALUES(1, 2, 3); |
|
|
INSERT INTO "(t1)" VALUES(4, 5, 6); |
|
|
} |
|
|
db close |
|
|
|
|
|
do_test 3.2 { |
|
|
forcedelete rbu.db |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { |
|
|
CREATE TABLE "data_(t1)"(a, b, c, rbu_control); |
|
|
INSERT INTO "data_(t1)" VALUES(4, 8, 9, 0); |
|
|
} |
|
|
dbo close |
|
|
|
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
rbu step |
|
|
} {SQLITE_CONSTRAINT} |
|
|
|
|
|
do_test 3.3 { |
|
|
list [catch {rbu close} msg] $msg |
|
|
} {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: (t1).a}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_db |
|
|
do_execsql_test 4.1 { |
|
|
CREATE TABLE "(t1)"(a, b, c, PRIMARY KEY(c, b, a)); |
|
|
INSERT INTO "(t1)" VALUES(1, 2, 3); |
|
|
INSERT INTO "(t1)" VALUES(4, 5, 6); |
|
|
} |
|
|
db close |
|
|
|
|
|
do_test 4.2 { |
|
|
forcedelete rbu.db |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { |
|
|
CREATE TABLE "data_(t1)"(a, b, c, rbu_control); |
|
|
INSERT INTO "data_(t1)" VALUES(7, 8, 9, 0); |
|
|
INSERT INTO "data_(t1)" VALUES(1, 2, 3, 1); |
|
|
} |
|
|
dbo close |
|
|
|
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
while {[rbu step]=="SQLITE_OK"} { } |
|
|
rbu close |
|
|
} {SQLITE_DONE} |
|
|
|
|
|
do_test 4.3 { |
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
} {SQLITE_DONE} |
|
|
|
|
|
do_test 4.4 { |
|
|
rbu close |
|
|
} {SQLITE_DONE} |
|
|
|
|
|
do_test 4.5.1 { |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { INSERT INTO rbu_state VALUES(100, 100) } |
|
|
dbo close |
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
} {SQLITE_CORRUPT} |
|
|
do_test 4.5.2 { |
|
|
list [catch {rbu close} msg] $msg |
|
|
} {1 SQLITE_CORRUPT} |
|
|
do_test 4.5.3 { |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { DELETE FROM rbu_state WHERE k = 100 } |
|
|
dbo close |
|
|
} {} |
|
|
|
|
|
|
|
|
|
|
|
do_test 4.6.1 { |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 } |
|
|
dbo close |
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
} {SQLITE_CORRUPT} |
|
|
do_test 4.6.2 { |
|
|
list [catch {rbu close} msg] $msg |
|
|
} {1 SQLITE_CORRUPT} |
|
|
do_test 4.6.3 { |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 } |
|
|
dbo close |
|
|
} {} |
|
|
|
|
|
do_test 4.7.1 { |
|
|
sqlite3 dbo rbu.db |
|
|
dbo eval { UPDATE rbu_state SET v = 1 WHERE k = 1 } |
|
|
dbo eval { UPDATE rbu_state SET v = 'nosuchtable' WHERE k = 2 } |
|
|
dbo close |
|
|
sqlite3rbu rbu test.db rbu.db |
|
|
rbu step |
|
|
} {SQLITE_ERROR} |
|
|
do_test 4.7.2 { |
|
|
list [catch {rbu close} msg] $msg |
|
|
} {1 {SQLITE_ERROR - rbu_state mismatch error}} |
|
|
|
|
|
finish_test |
|
|
|