]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure PRAGMA data_version is updated even if the cache is empty when
authordrh <drh@noemail.net>
Wed, 31 Dec 2014 14:18:48 +0000 (14:18 +0000)
committerdrh <drh@noemail.net>
Wed, 31 Dec 2014 14:18:48 +0000 (14:18 +0000)
another connection changes the database.

FossilOrigin-Name: cf48eb608af9102a8def2a5b7f5f7b348548116f

manifest
manifest.uuid
src/pager.c
test/pragma3.test

index 9942d4b320a1eddaec15b5d568aae88d67d95f19..18d0f09e4c44e2ab5a2edc37055e8439be3fcd3d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Do\snot\srun\spragma3.test\sas\spart\sof\sthe\smmap\spermutation.
-D 2014-12-31T09:52:15.410
+C Make\ssure\sPRAGMA\sdata_version\sis\supdated\seven\sif\sthe\scache\sis\sempty\swhen\nanother\sconnection\schanges\sthe\sdatabase.
+D 2014-12-31T14:18:48.679
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 7cd23e4fc91004a6bd081623e1bc6932e44828c0
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -216,7 +216,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
 F src/os_unix.c 08c0346d2ea5e5ffd5b1a796f9becf1976d648d7
 F src/os_win.c 91d3d08e33ec0258d180d4c8255492f47d15e007
 F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21
-F src/pager.c 2cbaf886a6157c53a8061ea7e677f81620ff46eb
+F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c
 F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77
 F src/parse.y 5dfead8aed90cb0c7c1115898ee2266804daff45
 F src/pcache.c b83d160ce81ca101f98f0d27498e6d6bd49f1599
@@ -785,7 +785,7 @@ F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54
 F test/permutations.test e1c603ec095e29de3d1f1566d704ea270f9c3f89
 F test/pragma.test aa16dedfe01c02c8895169012f7dfde9c163f0d5
 F test/pragma2.test aea7b3d82c76034a2df2b38a13745172ddc0bc13
-F test/pragma3.test 0ca2aea1499a7c2dcee235419e520d825dac958d
+F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c
 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552
 F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a
 F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d
@@ -1234,7 +1234,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 93094a68d3a6178779878cbbe0e5e09ef31a323f
-R 568e484006de3cb2669a32ac139fa8fe
-U dan
-Z 9ed2b5eb1c7f4568141d7b75c646d319
+P 94101011966243d599519a69c99c202ea31b928d
+R ce88be0f3eb17006a4da57569dcf8731
+U drh
+Z eb99526801ba8c2c5e7e84b0513387c7
index 9a0f1e309b3fea4a4c475218244c92d5620d8622..a48eb4758523bff0c4c19a06e6db8e42664e3a6e 100644 (file)
@@ -1 +1 @@
-94101011966243d599519a69c99c202ea31b928d
\ No newline at end of file
+cf48eb608af9102a8def2a5b7f5f7b348548116f
\ No newline at end of file
index 67b95f7186c31082e350a88bd4c4f79a260a00ac..2230174e5cb211ad99fd37a66e4318f4f7176252 100644 (file)
@@ -647,6 +647,7 @@ struct Pager {
   u8 doNotSpill;              /* Do not spill the cache when non-zero */
   u8 subjInMemory;            /* True to use in-memory sub-journals */
   u8 bUseFetch;               /* True to use xFetch() */
+  u8 hasBeenUsed;             /* True if any content previously read from this pager*/
   Pgno dbSize;                /* Number of pages in the database */
   Pgno dbOrigSize;            /* dbSize before the current transaction */
   Pgno dbFileSize;            /* Number of pages in the database file */
@@ -3897,7 +3898,7 @@ static int pagerAcquireMapPage(
   PgHdr **ppPage                  /* OUT: Acquired page object */
 ){
   PgHdr *p;                       /* Memory mapped page to return */
-
+  
   if( pPager->pMmapFreelist ){
     *ppPage = p = pPager->pMmapFreelist;
     pPager->pMmapFreelist = p->pDirty;
@@ -5128,16 +5129,12 @@ int sqlite3PagerSharedLock(Pager *pPager){
       );
     }
 
-    if( !pPager->tempFile && (
-        pPager->pBackup 
-     || sqlite3PcachePagecount(pPager->pPCache)>0 
-     || USEFETCH(pPager)
-    )){
-      /* The shared-lock has just been acquired on the database file
-      ** and there are already pages in the cache (from a previous
-      ** read or write transaction).  Check to see if the database
-      ** has been modified.  If the database has changed, flush the
-      ** cache.
+    if( !pPager->tempFile && pPager->hasBeenUsed ){
+      /* The shared-lock has just been acquired then check to
+      ** see if the database has been modified.  If the database has changed,
+      ** flush the cache.  The pPager->hasBeenUsed flag prevents this from
+      ** occurring on the very first access to a file, in order to save a
+      ** single unnecessary sqlite3OsRead() call at the start-up.
       **
       ** Database changes is detected by looking at 15 bytes beginning
       ** at offset 24 into the file.  The first 4 of these 16 bytes are
@@ -5302,6 +5299,7 @@ int sqlite3PagerAcquire(
   if( pgno==0 ){
     return SQLITE_CORRUPT_BKPT;
   }
+  pPager->hasBeenUsed = 1;
 
   /* If the pager is in the error state, return an error immediately. 
   ** Otherwise, request the page from the PCache layer. */
@@ -5451,6 +5449,7 @@ DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
   assert( pgno!=0 );
   assert( pPager->pPCache!=0 );
   pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
+  assert( pPage==0 || pPager->hasBeenUsed );
   return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
 }
 
index 4654578df2a8a0ef9807581d52151794c22dc706..b7ea4d3fc625c9d8f2ee87ef0080bf35a518f4a3 100644 (file)
@@ -64,6 +64,7 @@ do_execsql_test pragma3-130 {
   COMMIT;
   SELECT * FROM t1;
   PRAGMA data_version;
+  PRAGMA shrink_memory;
 } {1 1 1 100 200 300 400 500 1}
 
 # EVIDENCE-OF: R-63005-41812 The integer values returned by two