2015-02-16 12:48:34 +01:00
|
|
|
# 2015 February 16
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
|
2023-01-27 20:59:46 +01:00
|
|
|
source [file join [file dirname [info script]] rbu_common.tcl]
|
2023-02-04 22:25:17 +01:00
|
|
|
if_no_rbu_support { finish_test ; return }
|
2015-07-23 22:44:49 +02:00
|
|
|
set ::testprefix rbu11
|
2015-02-16 12:48:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
2015-07-23 22:44:49 +02:00
|
|
|
# Test that the xAccess() method of an rbu vfs handles queries other
|
2015-02-16 12:48:34 +01:00
|
|
|
# than SQLITE_ACCESS_EXISTS correctly. The test code below causes
|
|
|
|
# SQLite to call xAccess(SQLITE_ACCESS_READWRITE) on the directory
|
|
|
|
# path argument passed to "PRAGMA temp_store_directory".
|
|
|
|
#
|
|
|
|
do_test 1.1 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu_create_vfs -default rbu ""
|
2015-02-16 12:48:34 +01:00
|
|
|
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
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu_destroy_vfs rbu
|
2015-02-16 12:48:34 +01:00
|
|
|
} {}
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
2015-07-23 22:44:49 +02:00
|
|
|
# Try to trick rbu into operating on a database opened in wal mode.
|
2015-02-16 12:48:34 +01:00
|
|
|
#
|
|
|
|
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
|
|
|
|
|
2015-07-23 22:44:49 +02:00
|
|
|
forcedelete rbu.db
|
|
|
|
sqlite3 dbo rbu.db
|
2015-02-16 12:48:34 +01:00
|
|
|
dbo eval {
|
2015-07-23 22:44:49 +02:00
|
|
|
CREATE TABLE data_t1(a, b, c, rbu_control);
|
2015-02-16 12:48:34 +01:00
|
|
|
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 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2015-02-16 12:48:34 +01:00
|
|
|
} {SQLITE_ERROR}
|
|
|
|
|
|
|
|
do_test 2.4 {
|
2015-07-23 22:44:49 +02:00
|
|
|
list [catch {rbu close} msg] $msg
|
2015-02-16 12:48:34 +01:00
|
|
|
} {1 {SQLITE_ERROR - cannot update wal mode database}}
|
|
|
|
|
2015-02-16 22:13:19 +01:00
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test a constraint violation message with an unusual table name.
|
|
|
|
# Specifically, one for which the first character is a codepoint
|
|
|
|
# smaller than 30 (character '0').
|
|
|
|
#
|
|
|
|
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 {
|
2015-07-23 22:44:49 +02:00
|
|
|
forcedelete rbu.db
|
|
|
|
sqlite3 dbo rbu.db
|
2015-02-16 22:13:19 +01:00
|
|
|
dbo eval {
|
2015-07-23 22:44:49 +02:00
|
|
|
CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
|
2015-02-16 22:13:19 +01:00
|
|
|
INSERT INTO "data_(t1)" VALUES(4, 8, 9, 0);
|
|
|
|
}
|
|
|
|
dbo close
|
|
|
|
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
|
|
|
rbu step
|
2015-02-16 22:13:19 +01:00
|
|
|
} {SQLITE_CONSTRAINT}
|
|
|
|
|
|
|
|
do_test 3.3 {
|
2015-07-23 22:44:49 +02:00
|
|
|
list [catch {rbu close} msg] $msg
|
2015-02-16 22:13:19 +01:00
|
|
|
} {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: (t1).a}}
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
2015-07-23 22:44:49 +02:00
|
|
|
# Check that once an RBU update has been applied, attempting to apply
|
|
|
|
# it a second time is a no-op (as the state stored in the RBU database is
|
2015-02-16 22:13:19 +01:00
|
|
|
# "all steps completed").
|
|
|
|
#
|
|
|
|
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 {
|
2015-07-23 22:44:49 +02:00
|
|
|
forcedelete rbu.db
|
|
|
|
sqlite3 dbo rbu.db
|
2015-02-16 22:13:19 +01:00
|
|
|
dbo eval {
|
2015-07-23 22:44:49 +02:00
|
|
|
CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
|
2015-02-16 22:13:19 +01:00
|
|
|
INSERT INTO "data_(t1)" VALUES(7, 8, 9, 0);
|
|
|
|
INSERT INTO "data_(t1)" VALUES(1, 2, 3, 1);
|
|
|
|
}
|
|
|
|
dbo close
|
|
|
|
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
while {[rbu step]=="SQLITE_OK"} { }
|
|
|
|
rbu close
|
2015-02-16 22:13:19 +01:00
|
|
|
} {SQLITE_DONE}
|
|
|
|
|
|
|
|
do_test 4.3 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2015-02-16 22:13:19 +01:00
|
|
|
} {SQLITE_DONE}
|
|
|
|
|
|
|
|
do_test 4.4 {
|
2015-07-23 22:44:49 +02:00
|
|
|
rbu close
|
2015-02-16 22:13:19 +01:00
|
|
|
} {SQLITE_DONE}
|
|
|
|
|
2015-02-18 21:16:15 +01:00
|
|
|
do_test 4.5.1 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3 dbo rbu.db
|
|
|
|
dbo eval { INSERT INTO rbu_state VALUES(100, 100) }
|
2015-02-18 21:16:15 +01:00
|
|
|
dbo close
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2015-02-18 21:16:15 +01:00
|
|
|
} {SQLITE_CORRUPT}
|
|
|
|
do_test 4.5.2 {
|
2015-07-23 22:44:49 +02:00
|
|
|
list [catch {rbu close} msg] $msg
|
2015-02-18 21:16:15 +01:00
|
|
|
} {1 SQLITE_CORRUPT}
|
|
|
|
do_test 4.5.3 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3 dbo rbu.db
|
|
|
|
dbo eval { DELETE FROM rbu_state WHERE k = 100 }
|
2015-02-18 21:16:15 +01:00
|
|
|
dbo close
|
|
|
|
} {}
|
|
|
|
|
2015-07-23 22:44:49 +02:00
|
|
|
# Also, check that an invalid state value in the rbu_state table is
|
2015-02-16 22:13:19 +01:00
|
|
|
# detected and reported as corruption.
|
2015-02-18 21:16:15 +01:00
|
|
|
do_test 4.6.1 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3 dbo rbu.db
|
|
|
|
dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
|
2015-02-16 22:13:19 +01:00
|
|
|
dbo close
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2015-02-16 22:13:19 +01:00
|
|
|
} {SQLITE_CORRUPT}
|
2015-02-18 21:16:15 +01:00
|
|
|
do_test 4.6.2 {
|
2015-07-23 22:44:49 +02:00
|
|
|
list [catch {rbu close} msg] $msg
|
2015-02-16 22:13:19 +01:00
|
|
|
} {1 SQLITE_CORRUPT}
|
2015-02-18 21:16:15 +01:00
|
|
|
do_test 4.6.3 {
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3 dbo rbu.db
|
|
|
|
dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
|
2015-02-18 21:16:15 +01:00
|
|
|
dbo close
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test 4.7.1 {
|
2015-07-23 22:44:49 +02:00
|
|
|
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 }
|
2015-02-18 21:16:15 +01:00
|
|
|
dbo close
|
2015-07-23 22:44:49 +02:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2015-02-18 21:16:15 +01:00
|
|
|
} {SQLITE_ERROR}
|
|
|
|
do_test 4.7.2 {
|
2015-07-23 22:44:49 +02:00
|
|
|
list [catch {rbu close} msg] $msg
|
|
|
|
} {1 {SQLITE_ERROR - rbu_state mismatch error}}
|
2015-02-16 22:13:19 +01:00
|
|
|
|
2015-02-16 12:48:34 +01:00
|
|
|
finish_test
|