Ensure that an error is reported if an attempt is made to update a wal mode database via ota.

FossilOrigin-Name: 6fc5d4d26a603b3906f02ceea0f507780d0c35eb
This commit is contained in:
dan 2015-02-11 16:25:27 +00:00
parent cd73244144
commit 2e24971f2a
4 changed files with 107 additions and 9 deletions

82
ext/ota/otaA.test Normal file
View File

@ -0,0 +1,82 @@
# 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.
#
#***********************************************************************
#
# This file contains tests for the OTA module. More specifically, it
# contains tests to ensure that it is an error to attempt to update
# a wal mode database via OTA.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source $testdir/tester.tcl
set ::testprefix otaA
set db_sql {
CREATE TABLE t1(a PRIMARY KEY, b, c);
}
set ota_sql {
CREATE TABLE data_t1(a, b, c, ota_control);
INSERT INTO data_t1 VALUES(1, 2, 3, 0);
INSERT INTO data_t1 VALUES(4, 5, 6, 0);
INSERT INTO data_t1 VALUES(7, 8, 9, 0);
}
do_test 1.0 {
forcedelete test.db ota.db
sqlite3 db test.db
db eval $db_sql
db eval { PRAGMA journal_mode = wal }
db close
sqlite3 db ota.db
db eval $ota_sql
db close
sqlite3ota ota test.db ota.db
ota step
} {SQLITE_ERROR}
do_test 1.1 {
list [catch { ota close } msg] $msg
} {1 {SQLITE_ERROR - cannot update wal mode database}}
do_test 2.0 {
forcedelete test.db ota.db
sqlite3 db test.db
db eval $db_sql
db close
sqlite3 db ota.db
db eval $ota_sql
db close
sqlite3ota ota test.db ota.db
ota step
ota close
} {SQLITE_OK}
do_test 2.1 {
sqlite3 db test.db
db eval {PRAGMA journal_mode = wal}
db close
sqlite3ota ota test.db ota.db
ota step
} {SQLITE_ERROR}
do_test 2.2 {
list [catch { ota close } msg] $msg
} {1 {SQLITE_ERROR - cannot update wal mode database}}
finish_test

View File

@ -188,8 +188,10 @@ struct ota_file {
sqlite3_file *pReal; /* Underlying file handle */
ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */
sqlite3ota *pOta; /* Pointer to ota object (ota target only) */
int openFlags; /* Flags this file was opened with */
unsigned int iCookie; /* Cookie value for main db files */
unsigned char iWriteVer; /* "write-version" value for main db files */
int nShm; /* Number of entries in apShm[] array */
char **apShm; /* Array of mmap'd *-shm regions */
@ -2056,6 +2058,11 @@ sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta){
p->rc = sqlite3_exec(p->db, OTA_CREATE_STATE, 0, 0, &p->zErrmsg);
}
if( p->rc==SQLITE_OK && p->pTargetFd->iWriteVer>1 ){
p->rc = SQLITE_ERROR;
p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
}
if( p->rc==SQLITE_OK ){
pState = otaLoadState(p);
assert( pState || p->rc!=SQLITE_OK );
@ -2264,7 +2271,11 @@ static int otaVfsRead(
ota_file *p = (ota_file*)pFile;
int rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
/* These look like magic numbers. But they are stable, as they are part
** of the definition of the SQLite file format, which may not change. */
unsigned char *pBuf = (unsigned char*)zBuf;
p->iCookie = otaGetU32(&pBuf[24]);
p->iWriteVer = pBuf[19];
}
return rc;
}
@ -2281,7 +2292,11 @@ static int otaVfsWrite(
ota_file *p = (ota_file*)pFile;
int rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
/* These look like magic numbers. But they are stable, as they are part
** of the definition of the SQLite file format, which may not change. */
unsigned char *pBuf = (unsigned char*)zBuf;
p->iCookie = otaGetU32(&pBuf[24]);
p->iWriteVer = pBuf[19];
}
return rc;
}

View File

@ -1,5 +1,5 @@
C Further\stweaks\sto\swork\swith\szipvfs.
D 2015-02-10T20:00:38.125
C Ensure\sthat\san\serror\sis\sreported\sif\san\sattempt\sis\smade\sto\supdate\sa\swal\smode\sdatabase\svia\sota.
D 2015-02-11T16:25:27.816
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -133,8 +133,9 @@ F ext/ota/ota6.test 1fbba5fd46e3e0bfa5ae1d0caf9da27d15cb7cdf
F ext/ota/ota7.test 1fe2c5761705374530e29f70c39693076028221a
F ext/ota/ota8.test cd70e63a0c29c45c0906692827deafa34638feda
F ext/ota/ota9.test d3eee95dd836824d07a22e5efcdb7bf6e869358b
F ext/ota/otaA.test 95566a8d193113867b960eadf85b310937f2fe03
F ext/ota/otafault.test 508ba87c83d632670ac0f94371a465d4bb4d49dd
F ext/ota/sqlite3ota.c 1f96966839c57e6a6f4ca8e8a771b23fbf79b8f6
F ext/ota/sqlite3ota.c 7400075206e6cb8cbb32fc7268cb2fcf6321ea66
F ext/ota/sqlite3ota.h 1cc7201086fe65a36957740381485a24738c4077
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
F ext/rtree/rtree.c 14e6239434d4e3f65d3e90320713f26aa24e167f
@ -1253,7 +1254,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 e729668168f00325459bc2e9b515aa95e57f2754
R 245c10d0f1613c672374bc7bdeb81ab9
P 0f152416be792457c52417aeb531ac860d12a5bd
R d9bfc5d0f25bbcabd7abf7a0a51ab0ed
U dan
Z 8b6e26dd39381b8c315cf4c234f64cec
Z 85c9979bf4d433f3d16c5b8b0ec7a03f

View File

@ -1 +1 @@
0f152416be792457c52417aeb531ac860d12a5bd
6fc5d4d26a603b3906f02ceea0f507780d0c35eb