Update the PRAGMA data_version command so that it reponse to changes made

by a shared-cache database connection, and also to changes made by the same
database connection.  Add test cases to verify the new behavior.

FossilOrigin-Name: 44ee538374940c50198949f2cbb9213ba2375b6a
This commit is contained in:
drh 2014-12-20 14:34:02 +00:00
parent 0d339e44a0
commit d7107b3852
4 changed files with 108 additions and 19 deletions

View File

@ -1,5 +1,5 @@
C Adding\stest\scases\sfor\sthe\s"PRAGMA\sdata_version"\scommand.
D 2014-12-19T20:27:02.112
C Update\sthe\sPRAGMA\sdata_version\scommand\sso\sthat\sit\sreponse\sto\schanges\smade\nby\sa\sshared-cache\sdatabase\sconnection,\sand\salso\sto\schanges\smade\sby\sthe\ssame\ndatabase\sconnection.\s\sAdd\stest\scases\sto\sverify\sthe\snew\sbehavior.
D 2014-12-20T14:34:02.508
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -216,7 +216,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c fb587121840f690101336879adfa6d0b2cd0e8c7
F src/os_win.c ecb04a0dad2fa6fa659931a9d8f0f3aca33f908a
F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21
F src/pager.c abe022cd72e112a05db5fd1d6d46f5ed93284247
F src/pager.c 2cbaf886a6157c53a8061ea7e677f81620ff46eb
F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77
F src/parse.y 5dfead8aed90cb0c7c1115898ee2266804daff45
F src/pcache.c ace1b67632deeaa84859b4c16c27711dfb7db3d4
@ -785,7 +785,7 @@ F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54
F test/permutations.test 4e12d43f4639ea8a0e366d9c64e0009afe2eb544
F test/pragma.test aa16dedfe01c02c8895169012f7dfde9c163f0d5
F test/pragma2.test aea7b3d82c76034a2df2b38a13745172ddc0bc13
F test/pragma3.test 117ef9768f6c8d11823de7bbe3231b35c426b013
F test/pragma3.test af097524ab7fdac11d3a37a5bab4f947f2d5d16c
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 43db1f44bce5a0ee50197b95ab0d844540b69d86
R 2feb9c2cda6af5a5f57185acec7e4041
P c5fb7d6a106d46f10e71abe3a6d4243b21ed02a5
R 4d00079d15bfd5a1a2ef4485d7808f56
U drh
Z 8c3ff0ee7ae569dc5dbcf90ed4307270
Z 7090cd431f3e847d9d9c987c1e3b054c

View File

@ -1 +1 @@
c5fb7d6a106d46f10e71abe3a6d4243b21ed02a5
44ee538374940c50198949f2cbb9213ba2375b6a

View File

@ -664,7 +664,7 @@ struct Pager {
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
PagerSavepoint *aSavepoint; /* Array of active savepoints */
int nSavepoint; /* Number of elements in aSavepoint[] */
u32 nReset; /* Number of calls to pager_reset() */
u32 iDataVersion; /* Changes whenever database content changes */
char dbFileVers[16]; /* Changes whenever database file changes */
int nMmapOut; /* Number of mmap pages currently outstanding */
@ -1682,17 +1682,17 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
** Discard the entire contents of the in-memory page-cache.
*/
static void pager_reset(Pager *pPager){
pPager->nReset++;
pPager->iDataVersion++;
sqlite3BackupRestart(pPager->pBackup);
sqlite3PcacheClear(pPager->pPCache);
}
/*
** Return the pPager->nReset value
** Return the pPager->iDataVersion value
*/
u32 sqlite3PagerDataVersion(Pager *pPager){
assert( pPager->eState>PAGER_OPEN );
return pPager->nReset;
return pPager->iDataVersion;
}
/*
@ -6317,6 +6317,7 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){
}
PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
pPager->iDataVersion++;
rc = pager_end_transaction(pPager, pPager->setMaster, 1);
return pager_error(pPager, rc);
}

View File

@ -23,18 +23,34 @@ do_execsql_test pragma3-101 {
PRAGMA temp.data_version;
} {1}
# Writing is a no-op
# Writing to the pragma is a no-op
do_execsql_test pragma3-102 {
PRAGMA main.data_version=1234;
PRAGMA main.data_version;
} {1 1}
# EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
# an indication that the database file has been modified.
#
# EVIDENCE-OF: R-30058-27547 The integer values returned by two
# invocations of "PRAGMA data_version" will be different if changes
# where committed to that database in between the two invocations.
#
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# In this test, it response to two separate changes on the same database
# connection.
#
do_execsql_test pragma3-110 {
CREATE TABLE t1(a);
INSERT INTO t1 VALUES(100),(200),(300);
SELECT * FROM t1;
PRAGMA data_version;
} {100 200 300 1}
} {100 200 300 3}
sqlite3 db2 test.db
do_test pragma3-120 {
@ -48,8 +64,17 @@ do_execsql_test pragma3-130 {
INSERT INTO t1 VALUES(400),(500);
SELECT * FROM t1;
PRAGMA data_version;
} {100 200 300 400 500 1}
} {100 200 300 400 500 4}
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# In these test, it response to changes in a different database connection
# part of the same process.
#
do_test pragma3-140 {
db2 eval {
SELECT * FROM t1;
@ -58,13 +83,76 @@ do_test pragma3-140 {
SELECT * FROM t1;
PRAGMA data_version;
}
} {100 200 300 400 500 2 101 201 301 401 501 2}
} {100 200 300 400 500 2 101 201 301 401 501 3}
do_execsql_test pragma3-150 {
SELECT * FROM t1;
PRAGMA data_version;
} {101 201 301 401 501 2}
} {101 201 301 401 501 5}
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# This test verifies behavior when a separate process changes the database
# file.
#
do_test pragma3-200 {
set fd [open pragma3.txt wb]
puts $fd {
sqlite3 db test.db;
db eval {DELETE FROM t1 WHERE a>300};
db close;
exit;
}
close $fd
exec [info nameofexec] pragma3.txt
forcedelete pragma3.txt
db eval {
PRAGMA data_version;
SELECT * FROM t1;
}
} {6 101 201}
db2 close
db close
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# The next series of tests verifies the behavior for shared-cache
# database connections.
#
ifcapable shared_cache {
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
sqlite3 db test.db
sqlite3 db2 test.db
do_test pragma3-300 {
db eval {
PRAGMA data_version;
CREATE TABLE t3(a,b,c);
PRAGMA data_version;
}
} {1 2}
do_test pragma3-310 {
db2 eval {
PRAGMA data_version;
INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
SELECT * FROM t3;
PRAGMA data_version;
}
} {2 abc def ghi 3}
do_test pragma3-320 {
db eval {
PRAGMA data_version;
SELECT * FROM t3;
}
} {3 abc def ghi}
db2 close
sqlite3_enable_shared_cache $::enable_shared_cache
}
finish_test