/ Check-in [6fc5d4d2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Ensure that an error is reported if an attempt is made to update a wal mode database via ota.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ota-update-no-pager_ota_mode
Files: files | file ages | folders
SHA1: 6fc5d4d26a603b3906f02ceea0f507780d0c35eb
User & Date: dan 2015-02-11 16:25:27
Context
2015-02-11
16:54
Merge latest trunk changes with this branch. Closed-Leaf check-in: 0b63e8dc user: dan tags: ota-update-no-pager_ota_mode
16:25
Ensure that an error is reported if an attempt is made to update a wal mode database via ota. check-in: 6fc5d4d2 user: dan tags: ota-update-no-pager_ota_mode
2015-02-10
20:00
Further tweaks to work with zipvfs. check-in: 0f152416 user: dan tags: ota-update-no-pager_ota_mode
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added ext/ota/otaA.test.

            1  +# 2014 August 30
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# This file contains tests for the OTA module. More specifically, it
           13  +# contains tests to ensure that it is an error to attempt to update
           14  +# a wal mode database via OTA.
           15  +#
           16  +
           17  +if {![info exists testdir]} {
           18  +  set testdir [file join [file dirname [info script]] .. .. test]
           19  +}
           20  +source $testdir/tester.tcl
           21  +set ::testprefix otaA
           22  +
           23  +set db_sql {
           24  +  CREATE TABLE t1(a PRIMARY KEY, b, c);
           25  +}
           26  +set ota_sql {
           27  +  CREATE TABLE data_t1(a, b, c, ota_control);
           28  +  INSERT INTO data_t1 VALUES(1, 2, 3, 0);
           29  +  INSERT INTO data_t1 VALUES(4, 5, 6, 0);
           30  +  INSERT INTO data_t1 VALUES(7, 8, 9, 0);
           31  +}
           32  +
           33  +do_test 1.0 {
           34  +  forcedelete test.db ota.db
           35  +
           36  +  sqlite3 db test.db
           37  +  db eval $db_sql
           38  +  db eval { PRAGMA journal_mode = wal }
           39  +  db close
           40  +
           41  +  sqlite3 db ota.db
           42  +  db eval $ota_sql
           43  +  db close
           44  +
           45  +  sqlite3ota ota test.db ota.db
           46  +  ota step
           47  +} {SQLITE_ERROR}
           48  +do_test 1.1 {
           49  +  list [catch { ota close } msg] $msg
           50  +} {1 {SQLITE_ERROR - cannot update wal mode database}}
           51  +
           52  +do_test 2.0 {
           53  +  forcedelete test.db ota.db
           54  +
           55  +  sqlite3 db test.db
           56  +  db eval $db_sql
           57  +  db close
           58  +
           59  +  sqlite3 db ota.db
           60  +  db eval $ota_sql
           61  +  db close
           62  +
           63  +  sqlite3ota ota test.db ota.db
           64  +  ota step
           65  +  ota close
           66  +} {SQLITE_OK}
           67  +
           68  +do_test 2.1 {
           69  +  sqlite3 db test.db
           70  +  db eval {PRAGMA journal_mode = wal}
           71  +  db close
           72  +  sqlite3ota ota test.db ota.db
           73  +  ota step
           74  +} {SQLITE_ERROR}
           75  +
           76  +do_test 2.2 {
           77  +  list [catch { ota close } msg] $msg
           78  +} {1 {SQLITE_ERROR - cannot update wal mode database}}
           79  +
           80  +
           81  +finish_test
           82  +

Changes to ext/ota/sqlite3ota.c.

   184    184   };
   185    185   
   186    186   struct ota_file {
   187    187     sqlite3_file base;              /* sqlite3_file methods */
   188    188     sqlite3_file *pReal;            /* Underlying file handle */
   189    189     ota_vfs *pOtaVfs;               /* Pointer to the ota_vfs object */
   190    190     sqlite3ota *pOta;               /* Pointer to ota object (ota target only) */
          191  +
   191    192     int openFlags;                  /* Flags this file was opened with */
   192    193     unsigned int iCookie;           /* Cookie value for main db files */
          194  +  unsigned char iWriteVer;        /* "write-version" value for main db files */
   193    195   
   194    196     int nShm;                       /* Number of entries in apShm[] array */
   195    197     char **apShm;                   /* Array of mmap'd *-shm regions */
   196    198     const char *zWal;               /* Wal filename for this db file */
   197    199     char *zDel;                     /* Delete this when closing file */
   198    200   };
   199    201   
................................................................................
  2051   2053         otaOpenDatabase(p);
  2052   2054       }
  2053   2055   
  2054   2056       /* If it has not already been created, create the ota_state table */
  2055   2057       if( p->rc==SQLITE_OK ){
  2056   2058         p->rc = sqlite3_exec(p->db, OTA_CREATE_STATE, 0, 0, &p->zErrmsg);
  2057   2059       }
         2060  +
         2061  +    if( p->rc==SQLITE_OK && p->pTargetFd->iWriteVer>1 ){
         2062  +      p->rc = SQLITE_ERROR;
         2063  +      p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
         2064  +    }
  2058   2065   
  2059   2066       if( p->rc==SQLITE_OK ){
  2060   2067         pState = otaLoadState(p);
  2061   2068         assert( pState || p->rc!=SQLITE_OK );
  2062   2069         if( p->rc==SQLITE_OK ){
  2063   2070           if( pState->eStage==0 ){ 
  2064   2071             otaDeleteOalFile(p);
................................................................................
  2260   2267     void *zBuf, 
  2261   2268     int iAmt, 
  2262   2269     sqlite_int64 iOfst
  2263   2270   ){
  2264   2271     ota_file *p = (ota_file*)pFile;
  2265   2272     int rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
  2266   2273     if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
  2267         -    p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
         2274  +    /* These look like magic numbers. But they are stable, as they are part
         2275  +    ** of the definition of the SQLite file format, which may not change. */
         2276  +    unsigned char *pBuf = (unsigned char*)zBuf;
         2277  +    p->iCookie = otaGetU32(&pBuf[24]);
         2278  +    p->iWriteVer = pBuf[19];
  2268   2279     }
  2269   2280     return rc;
  2270   2281   }
  2271   2282   
  2272   2283   /*
  2273   2284   ** Write data to an otaVfs-file.
  2274   2285   */
................................................................................
  2277   2288     const void *zBuf, 
  2278   2289     int iAmt, 
  2279   2290     sqlite_int64 iOfst
  2280   2291   ){
  2281   2292     ota_file *p = (ota_file*)pFile;
  2282   2293     int rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
  2283   2294     if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
  2284         -    p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
         2295  +    /* These look like magic numbers. But they are stable, as they are part
         2296  +    ** of the definition of the SQLite file format, which may not change. */
         2297  +    unsigned char *pBuf = (unsigned char*)zBuf;
         2298  +    p->iCookie = otaGetU32(&pBuf[24]);
         2299  +    p->iWriteVer = pBuf[19];
  2285   2300     }
  2286   2301     return rc;
  2287   2302   }
  2288   2303   
  2289   2304   /*
  2290   2305   ** Truncate an otaVfs-file.
  2291   2306   */