/ Check-in [3dca8b9d]
Login

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

Overview
Comment:Allow the VACUUM following SQLITE_DBCONFIG_RESET_DATABASE to proceed even if the write-version in the header indicates that the database file is not writable.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3dca8b9d5ab1f35f17fc527d8f2a20b6bac989d1406c883d5b4d6719953ef6b4
User & Date: drh 2018-07-19 14:40:41
Context
2018-07-19
15:27
Avoid a branch in the commit logic that is unreachable when compiled without SQLITE_ENABLE_BATCH_ATOMIC_WRITE. check-in: 271b8980 user: drh tags: trunk
14:40
Allow the VACUUM following SQLITE_DBCONFIG_RESET_DATABASE to proceed even if the write-version in the header indicates that the database file is not writable. check-in: 3dca8b9d user: drh tags: trunk
11:44
Experimental fix for resetting databases that have been deemed read-only due to a corrupt "read-version" header field. Closed-Leaf check-in: e2394002 user: dan tags: exp-dbreset-fix
2018-07-18
19:09
Add the SQLITE_FCNTL_DATA_VERSION file control check-in: a5087c5c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  3311   3311     ** is already in a read-transaction and a read-transaction
  3312   3312     ** is requested, this is a no-op.
  3313   3313     */
  3314   3314     if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
  3315   3315       goto trans_begun;
  3316   3316     }
  3317   3317     assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
         3318  +
         3319  +  if( (p->db->flags & SQLITE_ResetDatabase) 
         3320  +   && sqlite3PagerIsreadonly(pBt->pPager)==0 
         3321  +  ){
         3322  +    pBt->btsFlags &= ~BTS_READ_ONLY;
         3323  +  }
  3318   3324   
  3319   3325     /* Write transactions are not possible on a read-only database */
  3320   3326     if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
  3321   3327       rc = SQLITE_READONLY;
  3322   3328       goto trans_begun;
  3323   3329     }
  3324   3330   

Changes to test/resetdb.test.

   202    202   
   203    203     set res
   204    204   } {1 2 3 4}
   205    205   
   206    206   do_execsql_test -db db2 630 {
   207    207     SELECT * FROM sqlite_master
   208    208   } {}
          209  +
          210  +#-------------------------------------------------------------------------
          211  +reset_db
          212  +
          213  +do_execsql_test 700 {
          214  +  PRAGMA page_size=512;
          215  +  CREATE TABLE t1(a,b,c);
          216  +  CREATE INDEX t1a ON t1(a);
          217  +  CREATE INDEX t1bc ON t1(b,c);
          218  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<10)
          219  +    INSERT INTO t1(a,b,c) SELECT x, randomblob(100),randomblob(100) FROM c;
          220  +  PRAGMA page_count;
          221  +  PRAGMA integrity_check;
          222  +} {19 ok}
          223  +
          224  +do_execsql_test 710 {
          225  +  UPDATE sqlite_dbpage SET data=
          226  +    X'53514C69746520666F726D61742033000200030100402020000000000000001300000000000000000000000300000004000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000D00000003017C0001D801AC017C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002E03061715110145696E6465787431626374310443524541544520494E4445582074316263204F4E20743128622C63292A0206171311013F696E64657874316174310343524541544520494E44455820743161204F4E20743128612926010617111101397461626C657431743102435245415445205441424C4520743128612C622C6329' WHERE pgno=1;
          227  +}
          228  +
          229  +do_execsql_test 720 {
          230  +  PRAGMA integrity_check;
          231  +} {ok}
          232  +
          233  +do_test 730 {
          234  +  sqlite3_db_config db RESET_DB 1
          235  +  db eval VACUUM
          236  +  sqlite3_db_config db RESET_DB 0
          237  +} {0}
          238  +
          239  +do_execsql_test 740 {
          240  +  PRAGMA page_count;
          241  +  PRAGMA integrity_check;
          242  +} {1 ok}
   209    243   
   210    244   finish_test
   211    245