2014-09-15 14:44:24 +04:00
|
|
|
# 2014 August 30
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
|
2014-09-19 22:08:39 +04:00
|
|
|
if {![info exists testdir]} {
|
|
|
|
set testdir [file join [file dirname [info script]] .. .. test]
|
|
|
|
}
|
2014-09-15 14:44:24 +04:00
|
|
|
source $testdir/tester.tcl
|
|
|
|
set ::testprefix ota3
|
|
|
|
|
|
|
|
|
|
|
|
# Run the OTA in file $ota on target database $target until completion.
|
|
|
|
#
|
|
|
|
proc run_ota {target ota} {
|
|
|
|
sqlite3ota ota $target $ota
|
|
|
|
while { [ota step]=="SQLITE_OK" } {}
|
|
|
|
ota close
|
|
|
|
}
|
|
|
|
|
|
|
|
forcedelete test.db-oal ota.db
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test that for an OTA to be applied, no corruption results if the
|
|
|
|
# affinities on the source and target table do not match.
|
|
|
|
#
|
|
|
|
do_execsql_test 1.0 {
|
|
|
|
CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
|
|
|
|
CREATE INDEX i1 ON x1(b, c);
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test 1.1 {
|
|
|
|
sqlite3 db2 ota.db
|
|
|
|
db2 eval {
|
|
|
|
CREATE TABLE data_x1(a, b, c, ota_control);
|
|
|
|
INSERT INTO data_x1 VALUES(1, '123', '123', 0);
|
|
|
|
INSERT INTO data_x1 VALUES(2, 123, 123, 0);
|
|
|
|
}
|
|
|
|
db2 close
|
|
|
|
run_ota test.db ota.db
|
|
|
|
} {SQLITE_DONE}
|
|
|
|
|
|
|
|
do_execsql_test 1.2 {
|
|
|
|
PRAGMA integrity_check;
|
|
|
|
} {ok}
|
|
|
|
|
2014-09-15 16:18:29 +04:00
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test that NULL values may not be inserted into INTEGER PRIMARY KEY
|
|
|
|
# columns.
|
|
|
|
#
|
|
|
|
forcedelete ota.db
|
|
|
|
reset_db
|
|
|
|
|
|
|
|
do_execsql_test 2.0 {
|
|
|
|
CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
|
|
|
|
CREATE INDEX i1 ON x1(b, c);
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test 2.1 {
|
|
|
|
sqlite3 db2 ota.db
|
|
|
|
db2 eval {
|
|
|
|
CREATE TABLE data_x1(a, b, c, ota_control);
|
|
|
|
INSERT INTO data_x1 VALUES(NULL, 'a', 'b', 0);
|
|
|
|
}
|
|
|
|
db2 close
|
|
|
|
list [catch { run_ota test.db ota.db } msg] $msg
|
|
|
|
} {1 {SQLITE_MISMATCH - datatype mismatch}}
|
|
|
|
|
|
|
|
do_execsql_test 2.2 {
|
|
|
|
PRAGMA integrity_check;
|
|
|
|
} {ok}
|
2014-09-15 14:44:24 +04:00
|
|
|
|
2014-09-15 19:22:32 +04:00
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test that missing columns are detected.
|
|
|
|
#
|
|
|
|
forcedelete ota.db
|
|
|
|
reset_db
|
|
|
|
|
|
|
|
do_execsql_test 2.0 {
|
|
|
|
CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c);
|
|
|
|
CREATE INDEX i1 ON x1(b, c);
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test 2.1 {
|
|
|
|
sqlite3 db2 ota.db
|
|
|
|
db2 eval {
|
|
|
|
CREATE TABLE data_x1(a, b, ota_control);
|
|
|
|
INSERT INTO data_x1 VALUES(1, 'a', 0);
|
|
|
|
}
|
|
|
|
db2 close
|
|
|
|
list [catch { run_ota test.db ota.db } msg] $msg
|
2014-11-27 21:09:46 +03:00
|
|
|
} {1 {SQLITE_ERROR - column missing from data_x1: c}}
|
2014-09-15 19:22:32 +04:00
|
|
|
|
|
|
|
do_execsql_test 2.2 {
|
|
|
|
PRAGMA integrity_check;
|
|
|
|
} {ok}
|
2014-09-15 14:44:24 +04:00
|
|
|
|
|
|
|
finish_test
|