/ Check-in [e193aced]
Login

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

Overview
Comment:Fix nolock and immutable so that they work even if READONLY is requested.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | win32-none
Files: files | file ages | folders
SHA1: e193aced2942e7405d0f45f90d4954b5663b4ba5
User & Date: drh 2014-05-07 15:32:03
Context
2014-05-07
15:46
Add the SQLITE_IOCAP_IMMUTABLE bit as a possible return value from the xDeviceCharacteristics method in the VFS. Add the "nolock" and "immutable" query parameters to URI filenames. check-in: 1a0d7d3d user: drh tags: trunk
15:32
Fix nolock and immutable so that they work even if READONLY is requested. Closed-Leaf check-in: e193aced user: drh tags: win32-none
15:09
Add test cases and documentation for the nolock and immutable query parameters. check-in: 19d56cba user: drh tags: win32-none
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  4672   4672       ** database file. The default page size is the maximum of:
  4673   4673       **
  4674   4674       **    + SQLITE_DEFAULT_PAGE_SIZE,
  4675   4675       **    + The value returned by sqlite3OsSectorSize()
  4676   4676       **    + The largest page size that can be written atomically.
  4677   4677       */
  4678   4678       if( rc==SQLITE_OK ){
         4679  +      int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
  4679   4680         if( !readOnly ){
  4680         -        int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
  4681   4681           setSectorSize(pPager);
  4682   4682           assert(SQLITE_DEFAULT_PAGE_SIZE<=SQLITE_MAX_DEFAULT_PAGE_SIZE);
  4683   4683           if( szPageDflt<pPager->sectorSize ){
  4684   4684             if( pPager->sectorSize>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
  4685   4685               szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
  4686   4686             }else{
  4687   4687               szPageDflt = (u32)pPager->sectorSize;
................................................................................
  4696   4696             for(ii=szPageDflt; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
  4697   4697               if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ){
  4698   4698                 szPageDflt = ii;
  4699   4699               }
  4700   4700             }
  4701   4701           }
  4702   4702   #endif
  4703         -        pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
  4704         -        if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
  4705         -         || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
  4706         -            vfsFlags |= SQLITE_OPEN_READONLY;
  4707         -            goto act_like_temp_file;
  4708         -        }
         4703  +      }
         4704  +      pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
         4705  +      if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
         4706  +       || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
         4707  +          vfsFlags |= SQLITE_OPEN_READONLY;
         4708  +          goto act_like_temp_file;
  4709   4709         }
  4710   4710       }
  4711   4711     }else{
  4712   4712       /* If a temporary file is requested, it is not opened immediately.
  4713   4713       ** In this case we accept the default page size and delay actually
  4714   4714       ** opening the file until the first call to OsWrite().
  4715   4715       **

Changes to test/nolock.test.

    63     63     tvfs_reset
    64     64     sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1
    65     65     db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}
    66     66     list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
    67     67          xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
    68     68   } {xLock 0 xUnlock 0 xCheckReservedLock 0}
    69     69   
           70  +do_test nolock-1.3 {
           71  +  db close
           72  +  tvfs_reset
           73  +  sqlite db file:test.db?nolock=0 -vfs tvfs -uri 1 -readonly 1
           74  +  db eval {SELECT * FROM t1}
           75  +  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
           76  +       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
           77  +} {xLock 2 xUnlock 2 xCheckReservedLock 0}
           78  +
           79  +do_test nolock-1.4 {
           80  +  db close
           81  +  tvfs_reset
           82  +  sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1 -readonly 1
           83  +  db eval {SELECT * FROM t1}
           84  +  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
           85  +       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
           86  +} {xLock 0 xUnlock 0 xCheckReservedLock 0}
           87  +
    70     88   #############################################################################
    71     89   # Verify that immutable=1 disables both locking and xAccess calls to the
    72     90   # journal files.
    73     91   #
    74     92   do_test nolock-2.0 {
    75     93     db close
    76     94     forcedelete test.db
................................................................................
   117    135   } {hello world 12345 67890}
   118    136   do_test nolock-2.22 {
   119    137     list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
   120    138          xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
   121    139          xAccess $::tvfs_calls(xAccess)
   122    140   } {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}
   123    141   
          142  +do_test nolock-2.31 {
          143  +  db2 close
          144  +  tvfs_reset
          145  +  sqlite3 db2 file:test.db?immutable=1 -vfs tvfs -uri 1 -readonly 1
          146  +  db2 eval {SELECT * FROM t1, t2}
          147  +} {hello world 12345 67890}
          148  +do_test nolock-2.32 {
          149  +  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
          150  +       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
          151  +       xAccess $::tvfs_calls(xAccess)
          152  +} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}
          153  +
   124    154   ############################################################################
   125    155   # Verify that the SQLITE_IOCAP_IMMUTABLE flag works
   126    156   #
   127    157   do_test nolock-3.1 {
   128    158     db2 close
   129    159     tvfs devchar immutable
   130    160     tvfs_reset
   131    161     sqlite3 db2 test.db -vfs tvfs
   132    162     db2 eval {SELECT * FROM t1, t2}
   133    163   } {hello world 12345 67890}
   134    164   do_test nolock-3.2 {
          165  +  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
          166  +       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
          167  +       xAccess $::tvfs_calls(xAccess)
          168  +} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}
          169  +
          170  +do_test nolock-3.11 {
          171  +  db2 close
          172  +  tvfs_reset
          173  +  sqlite3 db2 test.db -vfs tvfs -readonly 1
          174  +  db2 eval {SELECT * FROM t1, t2}
          175  +} {hello world 12345 67890}
          176  +do_test nolock-3.12 {
   135    177     list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
   136    178          xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
   137    179          xAccess $::tvfs_calls(xAccess)
   138    180   } {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}
   139    181   
   140    182   db2 close
   141    183   db close
   142    184   tvfs delete
   143    185   finish_test