mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Improve test coverage of ota code a bit.
FossilOrigin-Name: a438fa6c9ad2fb1d78ac747172d07455d6381387
This commit is contained in:
@@ -17,43 +17,66 @@ source $testdir/tester.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
set ::testprefix otafault
|
||||
|
||||
do_test 1.1 {
|
||||
forcedelete ota.db
|
||||
execsql {
|
||||
PRAGMA encoding = utf16;
|
||||
proc copy_if_exists {src target} {
|
||||
if {[file exists $src]} {
|
||||
forcecopy $src $target
|
||||
} else {
|
||||
forcedelete $target
|
||||
}
|
||||
}
|
||||
|
||||
foreach {tn2 setup sql expect} {
|
||||
1 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
CREATE INDEX t1cb ON t1(c, b);
|
||||
INSERT INTO t1 VALUES(1, 1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3, 3);
|
||||
|
||||
CREATE TABLE ota.data_t1(a, b, c, ota_control);
|
||||
INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
|
||||
INSERT INTO data_t1 VALUES(3, 'three', NULL, '.x.');
|
||||
INSERT INTO data_t1 VALUES(4, 4, 4, 0);
|
||||
} {SELECT * FROM t1} {1 1 1 3 three 3 4 4 4}
|
||||
|
||||
2 {
|
||||
CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
|
||||
CREATE INDEX t2cb ON t1(c, b);
|
||||
CREATE INDEX t2cb ON t2(c, b);
|
||||
INSERT INTO t2 VALUES('a', 'a', 'a');
|
||||
INSERT INTO t2 VALUES('b', 'b', 'b');
|
||||
INSERT INTO t2 VALUES('c', 'c', 'c');
|
||||
|
||||
ATTACH 'ota.db' AS ota;
|
||||
CREATE TABLE ota.data_t1(a, b, c, ota_control);
|
||||
CREATE TABLE ota.data_t2(a, b, c, ota_control);
|
||||
|
||||
INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
|
||||
INSERT INTO data_t1 VALUES(3, 'three', NULL, '.x.');
|
||||
INSERT INTO data_t1 VALUES(4, 4, 4, 0);
|
||||
|
||||
INSERT INTO data_t2 VALUES('b', NULL, NULL, 1);
|
||||
INSERT INTO data_t2 VALUES('c', 'see', NULL, '.x.');
|
||||
INSERT INTO data_t2 VALUES('d', 'd', 'd', 0);
|
||||
} {SELECT * FROM t2} {a a a c see c d d d}
|
||||
|
||||
3 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
|
||||
CREATE INDEX t1cb ON t1(c, b);
|
||||
CREATE INDEX t2cb ON t2(c, b);
|
||||
|
||||
CREATE TABLE ota.data_t1(a, b, c, ota_control);
|
||||
CREATE TABLE ota.data_t2(a, b, c, ota_control);
|
||||
INSERT INTO data_t1 VALUES(1, 2, 3, 0);
|
||||
INSERT INTO data_t2 VALUES(4, 5, 6, 0);
|
||||
} {SELECT * FROM t1 UNION ALL SELECT * FROM t2} {1 2 3 4 5 6}
|
||||
|
||||
} {
|
||||
catch {db close}
|
||||
forcedelete ota.db test.db
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA encoding = utf16;
|
||||
ATTACH 'ota.db' AS ota;
|
||||
}
|
||||
execsql $setup
|
||||
db close
|
||||
|
||||
forcecopy test.db test.db.bak
|
||||
forcecopy ota.db ota.db.bak
|
||||
} {}
|
||||
|
||||
sqlite3_shutdown
|
||||
set lookaside_config [sqlite3_config_lookaside 0 0]
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
|
||||
foreach {tn f reslist} {
|
||||
1 oom-tra* {
|
||||
@@ -63,6 +86,7 @@ foreach {tn f reslist} {
|
||||
{1 SQLITE_IOERR_NOMEM}
|
||||
{1 {SQLITE_NOMEM - unable to open a temporary database file for storing temporary tables}}
|
||||
}
|
||||
|
||||
2 ioerr-* {
|
||||
{0 SQLITE_DONE}
|
||||
{1 {SQLITE_IOERR - disk I/O error}}
|
||||
@@ -75,7 +99,14 @@ foreach {tn f reslist} {
|
||||
{1 {SQLITE_IOERR - unable to open database: ota.db}}
|
||||
}
|
||||
} {
|
||||
do_faultsim_test 2 -faults $::f -prep {
|
||||
|
||||
catch {db close}
|
||||
sqlite3_shutdown
|
||||
set lookaside_config [sqlite3_config_lookaside 0 0]
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
|
||||
do_faultsim_test 2.$tn2 -faults $::f -prep {
|
||||
catch { db close }
|
||||
forcedelete test.db-journal test.db-wal ota.db-journal ota.db-wal
|
||||
forcecopy test.db.bak test.db
|
||||
@@ -89,23 +120,15 @@ foreach {tn f reslist} {
|
||||
if {$testrc==0} {
|
||||
sqlite3 db test.db
|
||||
faultsim_integrity_check
|
||||
set res [db eval {
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM t2;
|
||||
}]
|
||||
set expected [list {*}{
|
||||
1 1 1 3 three 3 4 4 4
|
||||
a a a c see c d d d
|
||||
}]
|
||||
|
||||
if {$res != $expected} {
|
||||
set res [db eval $::sql]
|
||||
if {$res != [list {*}$::expect]} {
|
||||
puts ""
|
||||
puts "res: $res"
|
||||
puts "exp: $expected"
|
||||
puts "exp: $expect"
|
||||
error "data not as expected!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch {db close}
|
||||
sqlite3_shutdown
|
||||
@@ -113,12 +136,7 @@ sqlite3_config_lookaside {*}$lookaside_config
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
|
||||
proc copy_if_exists {src target} {
|
||||
if {[file exists $src]} {
|
||||
forcecopy $src $target
|
||||
} else {
|
||||
forcedelete $target
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for {set iStep 0} {$iStep<=21} {incr iStep} {
|
||||
@@ -137,7 +155,7 @@ for {set iStep 0} {$iStep<=21} {incr iStep} {
|
||||
copy_if_exists test.db-oal test.db.bak.2-oal
|
||||
copy_if_exists ota.db ota.db.bak.2
|
||||
|
||||
do_faultsim_test 3.$iStep -faults oom-trans* -prep {
|
||||
do_faultsim_test 3.$tn.$iStep -faults $::f -prep {
|
||||
catch { db close }
|
||||
forcedelete test.db-journal test.db-wal ota.db-journal ota.db-wal
|
||||
copy_if_exists test.db.bak.2 test.db
|
||||
@@ -149,24 +167,13 @@ for {set iStep 0} {$iStep<=21} {incr iStep} {
|
||||
while {[ota step] == "SQLITE_OK"} {}
|
||||
ota close
|
||||
} -test {
|
||||
faultsim_test_result {0 SQLITE_DONE} \
|
||||
{1 {SQLITE_NOMEM - out of memory}} \
|
||||
{1 SQLITE_NOMEM} \
|
||||
{1 SQLITE_IOERR_NOMEM} \
|
||||
{1 {SQLITE_NOMEM - unable to open a temporary database file for storing temporary tables}}
|
||||
faultsim_test_result {*}$::reslist
|
||||
|
||||
if {$testrc==0} {
|
||||
sqlite3 db test.db
|
||||
faultsim_integrity_check
|
||||
set res [db eval {
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM t2;
|
||||
}]
|
||||
set expected [list {*}{
|
||||
1 1 1 3 three 3 4 4 4
|
||||
a a a c see c d d d
|
||||
}]
|
||||
|
||||
if {$res != $expected} {
|
||||
set res [db eval $::sql]
|
||||
if {$res != [list {*}$::expect]} {
|
||||
puts ""
|
||||
puts "res: $res"
|
||||
puts "exp: $expected"
|
||||
@@ -174,7 +181,7 @@ for {set iStep 0} {$iStep<=21} {incr iStep} {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
@@ -573,86 +573,83 @@ static char *otaStrndup(const char *zStr, int *pRc){
|
||||
** return OTA_PK_NONE
|
||||
** }
|
||||
*/
|
||||
static int otaTableType(
|
||||
sqlite3 *db,
|
||||
static void otaTableType(
|
||||
sqlite3ota *p,
|
||||
const char *zTab,
|
||||
int *peType,
|
||||
int *piPk
|
||||
){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
int rc = SQLITE_OK;
|
||||
int rc2;
|
||||
char *zSql = 0;
|
||||
/*
|
||||
** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q)
|
||||
** 1) PRAGMA index_list = ?
|
||||
** 2) SELECT count(*) FROM sqlite_master where name=%Q
|
||||
** 3) PRAGMA table_info = ?
|
||||
*/
|
||||
sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
|
||||
|
||||
*peType = OTA_PK_NOTABLE;
|
||||
*piPk = 0;
|
||||
zSql = sqlite3_mprintf(
|
||||
|
||||
assert( p->rc==SQLITE_OK );
|
||||
p->rc = prepareFreeAndCollectError(p->db, &aStmt[0], &p->zErrmsg,
|
||||
sqlite3_mprintf(
|
||||
"SELECT (sql LIKE 'create virtual%%')"
|
||||
" FROM main.sqlite_master"
|
||||
" WHERE name=%Q", zTab);
|
||||
if( zSql==0 ) return SQLITE_NOMEM;
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
||||
sqlite3_free(zSql);
|
||||
zSql = 0;
|
||||
if( pStmt==0 ) goto otaTableType_end;
|
||||
if( sqlite3_step(pStmt)!=SQLITE_ROW ){
|
||||
goto otaTableType_end; /* no such table */
|
||||
" FROM sqlite_master"
|
||||
" WHERE name=%Q", zTab
|
||||
));
|
||||
if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
|
||||
/* Either an error, or no such table. */
|
||||
goto otaTableType_end;
|
||||
}
|
||||
if( sqlite3_column_int(pStmt,0) ){
|
||||
if( sqlite3_column_int(aStmt[0], 0) ){
|
||||
*peType = OTA_PK_VTAB; /* virtual table */
|
||||
goto otaTableType_end;
|
||||
}
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
if( rc ) return rc;
|
||||
zSql = sqlite3_mprintf("PRAGMA index_list=%Q",zTab);
|
||||
if( zSql==0 ) return SQLITE_NOMEM;
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
||||
sqlite3_free(zSql);
|
||||
zSql = 0;
|
||||
if( pStmt==0 ) goto otaTableType_end;
|
||||
while( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
const u8 *zOrig = sqlite3_column_text(pStmt,3);
|
||||
if( zOrig && zOrig[0]=='p' ){
|
||||
zSql = sqlite3_mprintf("SELECT rootpage FROM main.sqlite_master"
|
||||
" WHERE name=%Q", sqlite3_column_text(pStmt,1));
|
||||
if( zSql==0 ){ rc = SQLITE_NOMEM; goto otaTableType_end; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
if( rc ) return rc;
|
||||
if( zSql ){
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
||||
sqlite3_free(zSql);
|
||||
zSql = 0;
|
||||
if( pStmt==0 ) goto otaTableType_end;
|
||||
if( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
*piPk = sqlite3_column_int(pStmt, 0);
|
||||
*peType = OTA_PK_EXTERNAL; /* external PK index */
|
||||
|
||||
p->rc = prepareFreeAndCollectError(p->db, &aStmt[1], &p->zErrmsg,
|
||||
sqlite3_mprintf("PRAGMA index_list=%Q",zTab)
|
||||
);
|
||||
if( p->rc ) goto otaTableType_end;
|
||||
while( sqlite3_step(aStmt[1])==SQLITE_ROW ){
|
||||
const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
|
||||
const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
|
||||
if( zOrig && zIdx && zOrig[0]=='p' ){
|
||||
p->rc = prepareFreeAndCollectError(p->db, &aStmt[2], &p->zErrmsg,
|
||||
sqlite3_mprintf(
|
||||
"SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
|
||||
));
|
||||
if( p->rc==SQLITE_OK ){
|
||||
if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
|
||||
*piPk = sqlite3_column_int(aStmt[2], 0);
|
||||
*peType = OTA_PK_EXTERNAL;
|
||||
}else{
|
||||
*peType = OTA_PK_WITHOUT_ROWID; /* WITHOUT ROWID table */
|
||||
*peType = OTA_PK_WITHOUT_ROWID;
|
||||
}
|
||||
}else{
|
||||
zSql = sqlite3_mprintf("PRAGMA table_info=%Q", zTab);
|
||||
if( zSql==0 ) return SQLITE_NOMEM;
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
||||
sqlite3_free(zSql);
|
||||
zSql = 0;
|
||||
if( pStmt==0 ) goto otaTableType_end;
|
||||
*peType = OTA_PK_NONE; /* (default) implicit ROWID */
|
||||
while( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
if( sqlite3_column_int(pStmt,5)>0 ){
|
||||
*peType = OTA_PK_IPK; /* explicit IPK column */
|
||||
break;
|
||||
}
|
||||
goto otaTableType_end;
|
||||
}
|
||||
}
|
||||
|
||||
otaTableType_end:
|
||||
sqlite3_free(zSql);
|
||||
rc2 = sqlite3_finalize(pStmt);
|
||||
return rc ? rc : rc2;
|
||||
p->rc = prepareFreeAndCollectError(p->db, &aStmt[3], &p->zErrmsg,
|
||||
sqlite3_mprintf("PRAGMA table_info=%Q",zTab)
|
||||
);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
while( sqlite3_step(aStmt[3])==SQLITE_ROW ){
|
||||
if( sqlite3_column_int(aStmt[3],5)>0 ){
|
||||
*peType = OTA_PK_IPK; /* explicit IPK column */
|
||||
goto otaTableType_end;
|
||||
}
|
||||
}
|
||||
*peType = OTA_PK_NONE;
|
||||
}
|
||||
|
||||
otaTableType_end: {
|
||||
int i;
|
||||
for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
|
||||
int rc2 = sqlite3_finalize(aStmt[i]);
|
||||
if( p->rc==SQLITE_OK ) p->rc = rc2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -676,7 +673,7 @@ static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){
|
||||
|
||||
/* Figure out the type of table this step will deal with. */
|
||||
assert( pIter->eType==0 );
|
||||
p->rc = otaTableType(p->db, pIter->zTbl, &pIter->eType, &pIter->iPkTnum);
|
||||
otaTableType(p, pIter->zTbl, &pIter->eType, &pIter->iPkTnum);
|
||||
if( p->rc ) return p->rc;
|
||||
|
||||
assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK
|
||||
@@ -1103,7 +1100,7 @@ static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){
|
||||
rc = sqlite3_finalize(pXList);
|
||||
if( p->rc==SQLITE_OK ) p->rc = rc;
|
||||
|
||||
while( p->rc==SQLITE_OK && pXInfo && SQLITE_ROW==sqlite3_step(pXInfo) ){
|
||||
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
|
||||
if( sqlite3_column_int(pXInfo, 5) ){
|
||||
/* int iCid = sqlite3_column_int(pXInfo, 0); */
|
||||
const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2);
|
||||
@@ -1119,6 +1116,25 @@ static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function creates the second imposter table used when writing to
|
||||
** a table b-tree where the table has an external primary key. If the
|
||||
** iterator passed as the second argument does not currently point to
|
||||
** a table (not index) with an external primary key, this function is a
|
||||
** no-op.
|
||||
**
|
||||
** Assuming the iterator does point to a table with an external PK, this
|
||||
** function creates a WITHOUT ROWID imposter table named "ota_imposter2"
|
||||
** used to access that PK index. For example, if the target table is
|
||||
** declared as follows:
|
||||
**
|
||||
** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
|
||||
**
|
||||
** then the imposter table schema is:
|
||||
**
|
||||
** CREATE TABLE ota_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
|
||||
**
|
||||
*/
|
||||
static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){
|
||||
if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_EXTERNAL ){
|
||||
int tnum = pIter->iPkTnum; /* Root page of PK index */
|
||||
|
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
||||
C Add\sextra\stests\sand\sfixes\sfor\sota.
|
||||
D 2015-02-16T21:13:19.665
|
||||
C Improve\stest\scoverage\sof\sota\scode\sa\sbit.
|
||||
D 2015-02-17T20:49:42.756
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -135,8 +135,8 @@ F ext/ota/ota7.test 1fe2c5761705374530e29f70c39693076028221a
|
||||
F ext/ota/ota8.test cd70e63a0c29c45c0906692827deafa34638feda
|
||||
F ext/ota/ota9.test d3eee95dd836824d07a22e5efcdb7bf6e869358b
|
||||
F ext/ota/otaA.test ef4bfa8cfd4ed814ae86f7457b64aa2f18c90171
|
||||
F ext/ota/otafault.test fd3d4d9b9ed3cbe4461cde602e40f50825e0ee2a
|
||||
F ext/ota/sqlite3ota.c f378ebb435ce79bb5060907c3bc994c5b48cbb85
|
||||
F ext/ota/otafault.test 0c7565f69e5e379a5ebdcaea4056f0c69da1becf
|
||||
F ext/ota/sqlite3ota.c 0c6cb4cea1a9231bc488e9c84da201b796437af6
|
||||
F ext/ota/sqlite3ota.h 1cc7201086fe65a36957740381485a24738c4077
|
||||
F ext/ota/test_ota.c 5dd58e4e6eb3ae7b471566616d44b701971bce88
|
||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||
@@ -1256,7 +1256,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P 62dc1fffc38cb157c15105098749b6dd0198eb84
|
||||
R 26fc1fcf1b321dc2a4f4bbbaf0fa84e9
|
||||
P e0b7151962fedbcac975f2216fd6b33b995a8945
|
||||
R 13b826f0fe6f2960ec7719bf830cc36a
|
||||
U dan
|
||||
Z bb700675d8726f14df483f7f803a4d01
|
||||
Z 295fff9fbb7cdd54355b757b10496bab
|
||||
|
@@ -1 +1 @@
|
||||
e0b7151962fedbcac975f2216fd6b33b995a8945
|
||||
a438fa6c9ad2fb1d78ac747172d07455d6381387
|
Reference in New Issue
Block a user