SQLite

Check-in [e193aced29]
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
Timelines: family | ancestors | descendants | both | win32-none
Files: files | file ages | folders
SHA1: e193aced2942e7405d0f45f90d4954b5663b4ba5
User & Date: drh 2014-05-07 15:32:03.879
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: 1a0d7d3d9d user: drh tags: trunk)
15:32
Fix nolock and immutable so that they work even if READONLY is requested. (Closed-Leaf check-in: e193aced29 user: drh tags: win32-none)
15:09
Add test cases and documentation for the nolock and immutable query parameters. (check-in: 19d56cbaca user: drh tags: win32-none)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pager.c.
4672
4673
4674
4675
4676
4677
4678
4679
4680

4681
4682
4683
4684
4685
4686
4687
    ** database file. The default page size is the maximum of:
    **
    **    + SQLITE_DEFAULT_PAGE_SIZE,
    **    + The value returned by sqlite3OsSectorSize()
    **    + The largest page size that can be written atomically.
    */
    if( rc==SQLITE_OK ){
      if( !readOnly ){
        int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);

        setSectorSize(pPager);
        assert(SQLITE_DEFAULT_PAGE_SIZE<=SQLITE_MAX_DEFAULT_PAGE_SIZE);
        if( szPageDflt<pPager->sectorSize ){
          if( pPager->sectorSize>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
            szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
          }else{
            szPageDflt = (u32)pPager->sectorSize;







<
|
>







4672
4673
4674
4675
4676
4677
4678

4679
4680
4681
4682
4683
4684
4685
4686
4687
    ** database file. The default page size is the maximum of:
    **
    **    + SQLITE_DEFAULT_PAGE_SIZE,
    **    + The value returned by sqlite3OsSectorSize()
    **    + The largest page size that can be written atomically.
    */
    if( rc==SQLITE_OK ){

      int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
      if( !readOnly ){
        setSectorSize(pPager);
        assert(SQLITE_DEFAULT_PAGE_SIZE<=SQLITE_MAX_DEFAULT_PAGE_SIZE);
        if( szPageDflt<pPager->sectorSize ){
          if( pPager->sectorSize>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
            szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
          }else{
            szPageDflt = (u32)pPager->sectorSize;
4696
4697
4698
4699
4700
4701
4702

4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
          for(ii=szPageDflt; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
            if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ){
              szPageDflt = ii;
            }
          }
        }
#endif

        pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
        if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
         || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
            vfsFlags |= SQLITE_OPEN_READONLY;
            goto act_like_temp_file;
        }
      }
    }
  }else{
    /* If a temporary file is requested, it is not opened immediately.
    ** In this case we accept the default page size and delay actually
    ** opening the file until the first call to OsWrite().
    **







>
|
|
|
|
|
<







4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708

4709
4710
4711
4712
4713
4714
4715
          for(ii=szPageDflt; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
            if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ){
              szPageDflt = ii;
            }
          }
        }
#endif
      }
      pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
      if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
       || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
          vfsFlags |= SQLITE_OPEN_READONLY;
          goto act_like_temp_file;

      }
    }
  }else{
    /* If a temporary file is requested, it is not opened immediately.
    ** In this case we accept the default page size and delay actually
    ** opening the file until the first call to OsWrite().
    **
Changes to test/nolock.test.
63
64
65
66
67
68
69


















70
71
72
73
74
75
76
  tvfs_reset
  sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1
  db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
} {xLock 0 xUnlock 0 xCheckReservedLock 0}



















#############################################################################
# Verify that immutable=1 disables both locking and xAccess calls to the
# journal files.
#
do_test nolock-2.0 {
  db close
  forcedelete test.db







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  tvfs_reset
  sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1
  db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
} {xLock 0 xUnlock 0 xCheckReservedLock 0}

do_test nolock-1.3 {
  db close
  tvfs_reset
  sqlite db file:test.db?nolock=0 -vfs tvfs -uri 1 -readonly 1
  db eval {SELECT * FROM t1}
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
} {xLock 2 xUnlock 2 xCheckReservedLock 0}

do_test nolock-1.4 {
  db close
  tvfs_reset
  sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1 -readonly 1
  db eval {SELECT * FROM t1}
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock)
} {xLock 0 xUnlock 0 xCheckReservedLock 0}

#############################################################################
# Verify that immutable=1 disables both locking and xAccess calls to the
# journal files.
#
do_test nolock-2.0 {
  db close
  forcedelete test.db
117
118
119
120
121
122
123












124
125
126
127
128
129
130
131
132
133
134












135
136
137
138
139
140
141
142
143
} {hello world 12345 67890}
do_test nolock-2.22 {
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}













############################################################################
# Verify that the SQLITE_IOCAP_IMMUTABLE flag works
#
do_test nolock-3.1 {
  db2 close
  tvfs devchar immutable
  tvfs_reset
  sqlite3 db2 test.db -vfs tvfs
  db2 eval {SELECT * FROM t1, t2}
} {hello world 12345 67890}
do_test nolock-3.2 {












  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}

db2 close
db close
tvfs delete
finish_test







>
>
>
>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>









135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
} {hello world 12345 67890}
do_test nolock-2.22 {
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}

do_test nolock-2.31 {
  db2 close
  tvfs_reset
  sqlite3 db2 file:test.db?immutable=1 -vfs tvfs -uri 1 -readonly 1
  db2 eval {SELECT * FROM t1, t2}
} {hello world 12345 67890}
do_test nolock-2.32 {
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}

############################################################################
# Verify that the SQLITE_IOCAP_IMMUTABLE flag works
#
do_test nolock-3.1 {
  db2 close
  tvfs devchar immutable
  tvfs_reset
  sqlite3 db2 test.db -vfs tvfs
  db2 eval {SELECT * FROM t1, t2}
} {hello world 12345 67890}
do_test nolock-3.2 {
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}

do_test nolock-3.11 {
  db2 close
  tvfs_reset
  sqlite3 db2 test.db -vfs tvfs -readonly 1
  db2 eval {SELECT * FROM t1, t2}
} {hello world 12345 67890}
do_test nolock-3.12 {
  list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \
       xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \
       xAccess $::tvfs_calls(xAccess)
} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}

db2 close
db close
tvfs delete
finish_test