From: dan Date: Mon, 24 Jul 2017 19:23:20 +0000 (+0000) Subject: Only open a db in server-mode if there is a directory named "db-journal" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a12baadd15d1c58299b7f89809d3cb83aa1c2abb;p=thirdparty%2Fsqlite.git Only open a db in server-mode if there is a directory named "db-journal" in the file-system and the VFS is an exclusive locking VFS. FossilOrigin-Name: e77d29f64480179d7aae7d88adab2ba9ff042701e1f4e624a3a7775cb56a51cc --- diff --git a/manifest b/manifest index 2cae228e02..2ae61bcbaa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\strunk\schanges\swith\sthis\sbranch. -D 2017-07-19T18:54:21.843 +C Only\sopen\sa\sdb\sin\sserver-mode\sif\sthere\sis\sa\sdirectory\snamed\s"db-journal"\nin\sthe\sfile-system\sand\sthe\sVFS\sis\san\sexclusive\slocking\sVFS. +D 2017-07-24T19:23:20.202 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016 @@ -436,10 +436,10 @@ F src/os.c add02933b1dce7a39a005b00a2f5364b763e9a24 F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c d3c3a186ceb27d363f7a5e281ece4eb32b56e173a331e153a761d280034e3212 +F src/os_unix.c 98df292b72d8c15c6292be663ee917ac0316a0d9ec652e6e55e06bc4d83f84b7 F src/os_win.c 2a6c73eef01c51a048cc4ddccd57f981afbec18a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 7d0bec5dc1411cf3a5771d8608953f2eaa856dcd506c3a444060897139f7eb21 +F src/pager.c bd64887fbd1df4cdc503ccb1c9413ffdb7e7db9fb1dc787e170f3ddb784a0811 F src/pager.h 857d21f70acefc76e5bae4584f0133e754a2448b197d1e79b7179f26f9a11bc1 F src/parse.y 3a1babd6645a8103898a5e7e239dcf56cdafbdc25fd8133bb4a9160f9471d42d F src/pcache.c 62835bed959e2914edd26afadfecce29ece0e870 @@ -453,11 +453,11 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 4324a94573b1e29286f8121e4881db59eaedc014afeb274c8d3e07ed282e0e20 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c c6bf96a7f9d7d68f929de84738c599a30d0a725ab0b54420e70545743cd5ee7b -F src/server.c a5dbb0b06d046219e25f4f59998f6067e9d0761e4e06d35a70d0d7409c136c4f +F src/server.c 9b76ad62dffa41a9ddaaf23592499b967acae3c210090ba7c3fcbd1484f8389b F src/server.h a8477ae61546a9a4c8e06dd31936b06abf18bd086ae6a183ed57f721a3a194b4 F src/shell.c dd4494287b22ac5ab0654fdd5acb1f2172d2fe621f673a39229ddc31bd8d598f F src/shell.c.in b5725acacba95ccefa57b6d068f710e29ba8239c3aa704628a1902a1f729c175 -F src/sqlite.h.in 3f41373f19cb207d32bdb171fa051f86b779145a94fc51c4677e39c67ac3e17f +F src/sqlite.h.in 0c0d31b80e5d87b0ba3d0935ece97e4e34f2cee013b874890357c4e553007bd5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 967154985ed2ae62f90d9029bb5b5071793d847f1696a2ebe9e8cc0b042ae60b F src/sqliteInt.h 73847b09935e6d27d9b1a8f8bfa3eabba078fa7ff85b008a7d45a561c86f66b2 @@ -480,7 +480,7 @@ F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 F src/test_bestindex.c d23f80d334c59662af69191854c76b8d3d0c8c96 F src/test_blob.c f65ac717da2618691cf9dad094e6da0219dcd208 F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 -F src/test_config.c abf6fc1fe9d041b699578c42e3db81f8831c4f5b804f1927958102ee8f2b773e +F src/test_config.c 545983ba722b03d032a4d4d44e5fc26fa0558bea743c94e1f278e004a2ee5a9c F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 4e58dec2602d8e139ca08659f62a62450587cb58 @@ -1088,7 +1088,7 @@ F test/parser1.test 391b9bf9a229547a129c61ac345ed1a6f5eb1854 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff -F test/permutations.test 7340e77a5c5ed4f0d29f8c650e53ed642d19c1622b894b15e0e31167033e4354 +F test/permutations.test f00794b9821270e45b91ca5c2a82d36480992c49aa0ff32b0aa6d2f6db2a4d82 F test/pragma.test f274259d6393b6681eb433beb8dd39a26ec06a4431052a4880b43b84912a3f58 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 14c12bc5352b1e100e0b6b44f371053a81ccf8ed @@ -1164,12 +1164,12 @@ F test/selectE.test a8730ca330fcf40ace158f134f4fe0eb00c7edbf F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3 F test/selectG.test e8600e379589e85e9fefd2fe4d44a4cdd63f6982 F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 -F test/server2.test 277b4b1f142232e1f992ea17b587474c32e41e2f321c01acdd49ef5ffee99ee6 -F test/server3.test 3667fea050a248508d46b5eccb8a5561055f802016dc0d701e6b6f035ecc55ae -F test/server4.test 039d93f1d46011261edc16cb076673ca7acb377d81e5314df9267477d6dd93e7 -F test/server5.test 975197b00a22be438a8a56414420c6d144ed6b3725087c936d433c67aceea456 +F test/server2.test 38a33c71963d72aad64c6f4e89ed8f7de129b3b5bf75c5785e363dee8deabd35 +F test/server3.test ba6428594bbe32eafa015782a039dcacbf0f42db967e4093e4d2f6f74178a02d +F test/server4.test 97040670597948a695b1973537d770417589f1998bcbb3959302aaee3c211250 +F test/server5.test 2e554001145170094a19731a8ce2981d040cf44c947542b35d130e6e31256fca +F test/server_common.tcl 6e0e0348a87381770b548fcf8faf2d8c7b910120b08a1bfb565546f77293fa81 F test/servercrash.test 816c132b26af008067cab2913783f67006d4003e3988f3f3ee1075742f6e0a6c -F test/serverwal.test 2d066ba70db35e28f0115a57385cf606513c56d6e2861119c2defb7471e4e2d9 F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 @@ -1645,7 +1645,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 98a36f4cf127ceec423952a3d80d8d22163f128a5e6290cf6144c59029332944 d14fc621e918915bbf8e04597eb238ea78dff3d9c5eb4402cb88692d00dbdfee -R 12fce594a984131f0e3459cd80c5ba97 +P be0df0a65fc781fde6e94c9370b4819c703d3b270c707dd59e587a2a6f36c9f4 +R 1376469568361b44edcaf00907a78133 U dan -Z 7453e44f0ff2284a15fd0e8ee0880d92 +Z c66d5647b7f6dd06d2b7751c373422ff diff --git a/manifest.uuid b/manifest.uuid index bdad93087a..b615b3e71b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -be0df0a65fc781fde6e94c9370b4819c703d3b270c707dd59e587a2a6f36c9f4 \ No newline at end of file +e77d29f64480179d7aae7d88adab2ba9ff042701e1f4e624a3a7775cb56a51cc \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 472ab08f78..a2bcb2f75d 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3777,8 +3777,28 @@ static int unixGetTempname(int nBuf, char *zBuf); static int unixFileControl(sqlite3_file *id, int op, void *pArg){ unixFile *pFile = (unixFile*)id; switch( op ){ + case SQLITE_FCNTL_SERVER_MODE: { + int rc = SQLITE_OK; + int eServer = 0; + if( pFile->ctrlFlags | UNIXFILE_EXCL ){ + char *zJrnl = sqlite3_mprintf("%s-journal", pFile->zPath); + if( zJrnl==0 ){ + rc = SQLITE_NOMEM; + }else{ + struct stat buf; /* Used to hold return values of stat() */ + if( osStat(zJrnl, &buf) ){ + rc = SQLITE_IOERR_FSTAT; + }else{ + eServer = ((buf.st_mode & S_IFDIR) ? 1 : 0); + } + } + sqlite3_free(zJrnl); + } + *((int*)pArg) = eServer; + return rc; + } case SQLITE_FCNTL_FILEID: { - i64 *aId = (i64)pArg; + i64 *aId = (i64*)pArg; aId[0] = (i64)(pFile->pInode->fileId.dev); aId[1] = (i64)(pFile->pInode->fileId.ino); return SQLITE_OK; @@ -5630,6 +5650,15 @@ static int findCreateFileMode( zDb[nDb] = '\0'; rc = getFileMode(zDb, pMode, pUid, pGid); +#ifdef SQLITE_SERVER_EDITION + if( rc==SQLITE_IOERR_FSTAT ){ + while( nDb && zDb[nDb]!='/' ) nDb--; + if( nDb>8 && memcmp("-journal/", &zDb[nDb-8], 9)==0 ){ + zDb[nDb-8] = '\0'; + rc = getFileMode(zDb, pMode, pUid, pGid); + } + } +#endif }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ *pMode = 0600; }else if( flags & SQLITE_OPEN_URI ){ diff --git a/src/pager.c b/src/pager.c index 3f36dd78fa..3c17b565d5 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5066,7 +5066,7 @@ static int databaseIsUnmoved(Pager *pPager){ ** to determine whether or not a hot-journal file exists, the IO error ** code is returned and the value of *pExists is undefined. */ -static int hasHotJournal(Pager *pPager, int *pExists){ +static int hasHotJournal(Pager *pPager, int *pExists, int *peServer){ sqlite3_vfs * const pVfs = pPager->pVfs; int rc = SQLITE_OK; /* Return code */ int exists = 1; /* True if a journal file is present */ @@ -5087,6 +5087,13 @@ static int hasHotJournal(Pager *pPager, int *pExists){ if( rc==SQLITE_OK && exists ){ int locked = 0; /* True if some process holds a RESERVED lock */ +#ifdef SQLITE_SERVER_EDITION + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SERVER_MODE, peServer); + if( rc!=SQLITE_NOTFOUND ){ + if( rc!=SQLITE_OK || *peServer ) return rc; + } +#endif + /* Race condition here: Another process might have been holding the ** the RESERVED lock and have a journal open at the sqlite3OsAccess() ** call above, but then delete the journal and drop the lock before @@ -5200,12 +5207,9 @@ void sqlite3PagerServerJournal( sqlite3_file *jfd, const char *zJournal ){ - pPager->zJournal = zJournal; + pPager->zJournal = (char*)zJournal; pPager->jfd = jfd; } - -#else -# define pagerServerConnect(pPager) SQLITE_OK #endif @@ -5238,6 +5242,9 @@ void sqlite3PagerServerJournal( */ int sqlite3PagerSharedLock(Pager *pPager, int bReadonly){ int rc = SQLITE_OK; /* Return code */ +#ifdef SQLITE_SERVER_EDITION + int eServer = 0; +#endif /* This routine is only called from b-tree and only when there are no ** outstanding pages. This implies that the pager state should either @@ -5266,7 +5273,8 @@ int sqlite3PagerSharedLock(Pager *pPager, int bReadonly){ ** database file, then it either needs to be played back or deleted. */ if( pPager->eLock<=SHARED_LOCK ){ - rc = hasHotJournal(pPager, &bHotJournal); + rc = hasHotJournal(pPager, &bHotJournal, &eServer); + assert( bHotJournal==0 || eServer==0 ); } if( rc!=SQLITE_OK ){ goto failed; @@ -5399,6 +5407,7 @@ int sqlite3PagerSharedLock(Pager *pPager, int bReadonly){ if( rc!=SQLITE_IOERR_SHORT_READ ){ goto failed; } + rc = SQLITE_OK; memset(dbFileVers, 0, sizeof(dbFileVers)); } @@ -5417,7 +5426,11 @@ int sqlite3PagerSharedLock(Pager *pPager, int bReadonly){ } } - rc = pagerServerConnect(pPager); +#ifdef SQLITE_SERVER_EDITION + if( eServer ){ + rc = pagerServerConnect(pPager); + } +#endif /* If there is a WAL file in the file-system, open this database in WAL ** mode. Otherwise, the following function call is a no-op. @@ -5434,6 +5447,7 @@ int sqlite3PagerSharedLock(Pager *pPager, int bReadonly){ if( pagerIsServer(pPager) ){ assert( rc==SQLITE_OK ); assert( sqlite3PagerRefcount(pPager)==0 ); + assert( pagerUseWal(pPager)==0 ); pager_reset(pPager); rc = sqlite3ServerBegin(pPager->pServer, bReadonly); if( rc==SQLITE_OK ){ @@ -7734,6 +7748,7 @@ int sqlite3PagerIsServer(Pager *pPager){ return pagerIsServer(pPager); } int sqlite3PagerPagelock(Pager *pPager, Pgno pgno, int bWrite){ + if( pagerIsServer(pPager)==0 ) return SQLITE_OK; return sqlite3ServerLock(pPager->pServer, pgno, bWrite, 0); } #endif diff --git a/src/server.c b/src/server.c index 8ba5883903..cb319d966f 100644 --- a/src/server.c +++ b/src/server.c @@ -247,7 +247,7 @@ static int serverInitDatabase(Server *pNew){ int bExists = 0; ServerJournal *pJ = &pDb->aJrnl[i]; pJ->jfd = (sqlite3_file*)&a[ROUND8(pVfs->szOsFile)*i]; - pJ->zJournal = sqlite3_mprintf("%s-journal%d", zFilename, i); + pJ->zJournal = sqlite3_mprintf("%s-journal/%d-journal", zFilename, i); if( pJ->zJournal==0 ){ rc = SQLITE_NOMEM_BKPT; break; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 4547b1262e..872c934a50 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1045,6 +1045,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 #define SQLITE_FCNTL_PDB 30 #define SQLITE_FCNTL_FILEID 31 +#define SQLITE_FCNTL_SERVER_MODE 32 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE diff --git a/src/test_config.c b/src/test_config.c index 9ff84dcec0..91f9c9bcef 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -726,6 +726,12 @@ Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "sqlite_options", "uri_00_error", "0", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_SERVER_EDITION + Tcl_SetVar2(interp, "sqlite_options", "server", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "server", "0", TCL_GLOBAL_ONLY); +#endif + #define LINKVAR(x) { \ static const int cv_ ## x = SQLITE_ ## x; \ Tcl_LinkVar(interp, "SQLITE_" #x, (char *)&(cv_ ## x), \ diff --git a/test/permutations.test b/test/permutations.test index cbb84581bc..fcc5b61555 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -278,7 +278,7 @@ test_suite "server" -prefix "" -description { All server-edition tests. } -files [ test_set \ - select1.test server2.test server3.test server4.test + select1.test server2.test server3.test server4.test server5.test ] test_suite "fts5-light" -prefix "" -description { diff --git a/test/server2.test b/test/server2.test index 7ff13bc1b9..a1d7969855 100644 --- a/test/server2.test +++ b/test/server2.test @@ -17,6 +17,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix server2 +source $testdir/server_common.tcl +return_if_no_server + db close foreach f [glob -nocomplain test.db*] { forcedelete $f @@ -25,26 +28,26 @@ foreach f [glob -nocomplain test.db*] { #------------------------------------------------------------------------- # Check that the *-journal* files are deleted correctly. # -reset_db +server_reset_db do_execsql_test 1.0 { CREATE TABLE t1(a, b); } {} do_test 1.1 { - lsort [glob test.db*] -} {test.db test.db-journal0} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal} do_test 1.2 { db close - lsort [glob test.db*] -} {test.db} + lsort [glob -nocomplain test.db-journal/*] +} {} -sqlite3 db test.db +server_sqlite3 db test.db do_execsql_test 1.3 { CREATE TABLE t2(a, b); } {} -sqlite3 db2 test.db +server_sqlite3 db2 test.db do_test 1.4 { db eval { BEGIN; @@ -59,23 +62,23 @@ do_test 1.4 { do_test 1.5 { db2 eval COMMIT db eval COMMIT - lsort [glob test.db*] -} {test.db test.db-journal0 test.db-journal1} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal test.db-journal/1-journal} do_test 1.6 { db close - lsort [glob test.db*] -} {test.db test.db-journal0 test.db-journal1} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal test.db-journal/1-journal} do_test 1.7 { db2 close - lsort [glob test.db*] -} {test.db} + lsort [glob -nocomplain test.db-journal/*] +} {} #------------------------------------------------------------------------- # -reset_db -sqlite3 db2 test.db +server_reset_db +server_sqlite3 db2 test.db do_execsql_test 2.0 { CREATE TABLE t1(a, b); @@ -95,14 +98,14 @@ do_test 2.1 { } } {} do_test 2.2 { - lsort [glob test.db*] -} {test.db test.db-journal0 test.db-journal1} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal test.db-journal/1-journal} do_test 2.3.1 { db eval COMMIT } {} do_test 2.3.2 { db2 eval COMMIT } {} do_execsql_test 2.4 {SELECT * FROM t1, t2} {1 2 3 4} do_test 2.5 { - lsort [glob test.db*] -} {test.db test.db-journal0 test.db-journal1} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal test.db-journal/1-journal} do_test 2.6 { execsql {BEGIN} @@ -123,19 +126,18 @@ db2 close #------------------------------------------------------------------------- # -reset_db +server_reset_db do_execsql_test 3.0 { CREATE TABLE t1(a, b); } do_test 3.1 { - glob test.db* -} {test.db-journal0 test.db} + lsort [glob -nocomplain test.db-journal/*] +} {test.db-journal/0-journal} do_test 3.2 { db close - glob test.db* -} {test.db} - + lsort [glob -nocomplain test.db-journal/*] +} {} finish_test diff --git a/test/server3.test b/test/server3.test index 966ca1c454..19b72a54a0 100644 --- a/test/server3.test +++ b/test/server3.test @@ -18,30 +18,35 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl set testprefix server3 -db close - -do_multiclient_test tn { - if {$tn==1} continue - - do_test $tn.1 { - sql1 { CREATE TABLE t1(a, b) } - sql2 { CREATE TABLE t2(a, b) } - } {} - - do_test $tn.2 { - sql1 { - INSERT INTO t2 VALUES(1, 2); - BEGIN; - INSERT INTO t1 VALUES(1, 2); - } - } {} - - do_test $tn.3 { csql2 { SELECT * FROM t1 } } {1 {database is locked}} - do_test $tn.4 { csql2 { SELECT * FROM t1 } } {1 {database is locked}} - do_test $tn.5 { sql2 { SELECT * FROM t2 } } {1 2} - - -} +source $testdir/server_common.tcl +return_if_no_server + +server_reset_db +server_sqlite3 db2 test.db + +do_test 1.1 { + db eval { CREATE TABLE t1(a, b) } + db2 eval { CREATE TABLE t2(a, b) } +} {} + +do_test 1.2 { + db eval { + INSERT INTO t2 VALUES(1, 2); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + } +} {} + +do_test 1.3 { + list [catch { db2 eval { SELECT * FROM t1 } } msg] $msg +} {1 {database is locked}} +do_test 1.4 { + list [catch { db2 eval { SELECT * FROM t1 } } msg] $msg +} {1 {database is locked}} + +do_test 1.4 { + db2 eval { SELECT * FROM t2 } +} {1 2} finish_test diff --git a/test/server4.test b/test/server4.test index b9d7eb728f..afdeff76c8 100644 --- a/test/server4.test +++ b/test/server4.test @@ -19,9 +19,13 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/lock_common.tcl -set testprefix server3 +set testprefix server4 -sqlite3 db2 test.db +source $testdir/server_common.tcl +return_if_no_server + +server_reset_db +server_sqlite3 db2 test.db do_execsql_test 1.0 { CREATE TABLE t1(x); @@ -57,6 +61,5 @@ do_execsql_test -db db2 1.4 { SELECT * FROM t1; } {1 2 3} - finish_test diff --git a/test/server5.test b/test/server5.test index b34e11cab7..e053504f7f 100644 --- a/test/server5.test +++ b/test/server5.test @@ -11,8 +11,7 @@ # This file implements regression tests for SQLite library. # # The focus of this script is testing the server mode of SQLite. -# Specifically, that "BEGIN READONLY" starts a read-only MVCC -# transaction. +# Specifically, that "PRAGMA freelist_format" works. # @@ -24,10 +23,6 @@ do_execsql_test 1.0 { PRAGMA freelist_format; } {1} -explain_i { - PRAGMA freelist_format = 2; -} - do_execsql_test 1.1 { PRAGMA freelist_format = 2; } {2} @@ -57,7 +52,5 @@ do_execsql_test 1.6 { PRAGMA freelist_format = 1; } {2} - - finish_test diff --git a/test/server_common.tcl b/test/server_common.tcl new file mode 100644 index 0000000000..84cd6b27e4 --- /dev/null +++ b/test/server_common.tcl @@ -0,0 +1,35 @@ +# 2017 July 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +ifcapable !server { + proc return_if_no_server {} { + finish_test + return -code return + } + return +} else { + proc return_if_no_server {} {} +} + +proc server_sqlite3 {cmd file} { + sqlite3 $cmd $file -vfs unix-excl +} + +proc server_reset_db {} { + catch {db close} + forcedelete test.db test.db-journal test.db-wal + file mkdir test.db-journal + server_sqlite3 db test.db +} + + diff --git a/test/serverwal.test b/test/serverwal.test deleted file mode 100644 index 2c442361c7..0000000000 --- a/test/serverwal.test +++ /dev/null @@ -1,138 +0,0 @@ -# 2017 April 25 -# -# The author disclaims copyright to this source code. In place of -# a legal notice, here is a blessing: -# -# May you do good and not evil. -# May you find forgiveness for yourself and forgive others. -# May you share freely, never taking more than you give. -# -#*********************************************************************** -# This file implements regression tests for SQLite library. The -# focus of this script is testing the server mode of SQLite. -# - - -set testdir [file dirname $argv0] -source $testdir/tester.tcl -set testprefix serverwal - -# Check files are created and deleted as expected. -# -do_execsql_test 1.0 { - PRAGMA journal_mode = wal; -} {wal} -do_execsql_test 1.1 { - CREATE TABLE t1(a, b); -} -do_execsql_test 1.2 { - SELECT * FROM t1; -} {} -do_test 1.3 { - lsort [glob test.db*] -} {test.db test.db-hma test.db-shm test.db-wal} -do_test 1.4 { - db close - glob test.db* -} {test.db} - -#------------------------------------------------------------------------- -# Two concurrent transactions. -# -do_test 2.0 { - sqlite3 db test.db - sqlite3 db2 test.db - db eval { - CREATE TABLE t2(a, b); - } -} {} -do_test 2.1 { - execsql { - BEGIN; - INSERT INTO t1 VALUES(1, 2); - } db - execsql { - BEGIN; - INSERT INTO t2 VALUES(1, 2); - } db2 -} {} -do_test 2.2 { - execsql COMMIT db - execsql COMMIT db2 -} {} -db close -db2 close - -#------------------------------------------------------------------------- -# That the wal file can be wrapped around. -# -reset_db -do_execsql_test 3.0 { - PRAGMA journal_mode = wal; - CREATE TABLE ttt(a, b); - INSERT INTO ttt VALUES(1, 2); - INSERT INTO ttt VALUES(3, 4); - INSERT INTO ttt VALUES(5, 6); - INSERT INTO ttt VALUES(7, 8); - INSERT INTO ttt VALUES(9, 10); -} {wal} - -do_test 3.1 { - set N [file size test.db-wal] - execsql { - PRAGMA wal_checkpoint = restart; - INSERT INTO ttt VALUES(11, 12); - INSERT INTO ttt VALUES(13, 14); - } - expr {$N == [file size test.db-wal]} -} {1} - -#------------------------------------------------------------------------- -# That ROLLBACK appears to work. -# -reset_db -do_execsql_test 4.0 { - PRAGMA cache_size = 10; - CREATE TABLE ttt(a, b); - CREATE INDEX yyy ON ttt(b, a); - PRAGMA journal_mode = wal; - WITH s(i) AS ( - SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 - ) - INSERT INTO ttt SELECT randomblob(100), randomblob(100) FROM s; -} {wal} - -do_execsql_test 4.1 { - PRAGMA integrity_check; - BEGIN; - UPDATE ttt SET b=a; - ROLLBACK; - PRAGMA integrity_check; -} {ok ok} - -reset_db -do_execsql_test 5.1 { - CREATE TABLE xyz(a); - PRAGMA journal_mode = wal; - INSERT INTO xyz VALUES(1); - INSERT INTO xyz VALUES(2); - INSERT INTO xyz VALUES(3); -} {wal} - -breakpoint - -do_test 5.2 { - sqlite3 db2 test.db - execsql { SELECT * FROM xyz } db2 -} {1 2 3} - -do_execsql_test 5.3 { - PRAGMA wal_checkpoint = restart -} {0 0 0} - -do_test 5.4 { - execsql { SELECT * FROM xyz } db2 -} {1 2 3} - -finish_test -