/ Check-in [39247b14]
Login

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

Overview
Comment:Add extended error code SQLITE_READONLY_ROLLBACK. Returned if a read-only connection cannot read the database because doing so would require it to roll back a hot-journal.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 39247b14a52b0c0222fe5a848bf0aef0854058c4
User & Date: dan 2013-03-05 15:09:25
Context
2013-03-05
15:27
Do not attempt to set the permissions on an existing journal or wal file. Do this only immediately after creating a new file (or opening one zero bytes in size). Closed-Leaf check-in: 1d808690 user: dan tags: experimental
15:09
Add extended error code SQLITE_READONLY_ROLLBACK. Returned if a read-only connection cannot read the database because doing so would require it to roll back a hot-journal. check-in: 39247b14 user: dan tags: experimental
11:27
Fix a bug in the recent incremental-vacuum related changes. check-in: 717863fc user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  4823   4823       if( pPager->eLock<=SHARED_LOCK ){
  4824   4824         rc = hasHotJournal(pPager, &bHotJournal);
  4825   4825       }
  4826   4826       if( rc!=SQLITE_OK ){
  4827   4827         goto failed;
  4828   4828       }
  4829   4829       if( bHotJournal ){
         4830  +      if( pPager->readOnly ){
         4831  +        rc = SQLITE_READONLY_ROLLBACK;
         4832  +        goto failed;
         4833  +      }
         4834  +
  4830   4835         /* Get an EXCLUSIVE lock on the database file. At this point it is
  4831   4836         ** important that a RESERVED lock is not obtained on the way to the
  4832   4837         ** EXCLUSIVE lock. If it were, another process might open the
  4833   4838         ** database file, detect the RESERVED lock, and conclude that the
  4834   4839         ** database is safe to read while this process is still rolling the 
  4835   4840         ** hot-journal back.
  4836   4841         ** 

Changes to src/sqlite.h.in.

   474    474   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   475    475   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   476    476   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   477    477   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   478    478   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   479    479   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   480    480   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
          481  +#define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
   481    482   #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   482    483   #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
   483    484   #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
   484    485   #define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
   485    486   #define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
   486    487   #define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
   487    488   #define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))

Changes to src/test1.c.

   174    174       case SQLITE_IOERR_ACCESS:        zName = "SQLITE_IOERR_ACCESS";      break;
   175    175       case SQLITE_IOERR_CHECKRESERVEDLOCK:
   176    176                                  zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
   177    177       case SQLITE_IOERR_LOCK:          zName = "SQLITE_IOERR_LOCK";        break;
   178    178       case SQLITE_CORRUPT_VTAB:        zName = "SQLITE_CORRUPT_VTAB";      break;
   179    179       case SQLITE_READONLY_RECOVERY:   zName = "SQLITE_READONLY_RECOVERY"; break;
   180    180       case SQLITE_READONLY_CANTLOCK:   zName = "SQLITE_READONLY_CANTLOCK"; break;
          181  +    case SQLITE_READONLY_ROLLBACK:   zName = "SQLITE_READONLY_ROLLBACK"; break;
   181    182       default:                         zName = "SQLITE_Unknown";           break;
   182    183     }
   183    184     return zName;
   184    185   }
   185    186   #define t1ErrorName sqlite3TestErrorName
   186    187   
   187    188   /*

Changes to test/misc7.test.

   484    484   #
   485    485   do_test misc7-21.1 {
   486    486     set zFile [file join [get_pwd] "[string repeat abcde 104].db"]
   487    487     set rc [catch {sqlite3 db2 $zFile} msg]
   488    488     list $rc $msg
   489    489   } {1 {unable to open database file}}
   490    490   
          491  +# Try to do hot-journal rollback with a read-only connection. The 
          492  +# error code should be SQLITE_READONLY_ROLLBACK.
          493  +#
          494  +do_test misc7-22.1 {
          495  +  db close
          496  +  forcedelete test.db copy.db-journal
          497  +  sqlite3 db test.db
          498  +  execsql {
          499  +    CREATE TABLE t1(a, b);
          500  +    INSERT INTO t1 VALUES(1, 2);
          501  +    INSERT INTO t1 VALUES(3, 4);
          502  +  }
          503  +  db close
          504  +  sqlite3 db test.db -readonly 1
          505  +  catchsql {
          506  +    INSERT INTO t1 VALUES(5, 6);
          507  +  }
          508  +} {1 {attempt to write a readonly database}}
          509  +do_test misc7-22.2 { execsql { SELECT * FROM t1 } } {1 2 3 4}
          510  +do_test misc7-22.3 { 
          511  +  set fd [open test.db-journal w]
          512  +  puts $fd [string repeat abc 1000]
          513  +  close $fd
          514  +  catchsql { SELECT * FROM t1 }
          515  +} {1 {attempt to write a readonly database}}
          516  +do_test misc7-22.4 { 
          517  +  sqlite3_extended_errcode db
          518  +} SQLITE_READONLY_ROLLBACK
   491    519   
   492    520   db close
   493    521   forcedelete test.db
   494    522   
   495    523   finish_test