Added support for proxy file locking style

Added pragma support for controlling proxy file locking
Added file control access to last errno and proxy locking
Added support for TMPDIR environment variable
Extended unit tests to cover new proxy locking pragmas and file control features (CVS 5934)

FossilOrigin-Name: b9bc36d3d5e35821ef69c0881a84c0afed253c9e
This commit is contained in:
aswift 2008-11-21 00:10:35 +00:00
parent d164fd3483
commit aebf413d9a
15 changed files with 1580 additions and 200 deletions

View File

@ -1,5 +1,5 @@
C When\sa\smemory\sallocation\sfails\son\sthe\s%Q\sconversion\sin\ssqlite3_mprintf(),\nmake\ssure\sthe\serror\sis\sreported\sback\sup\sthe\scall\sstack.\s(CVS\s5933)
D 2008-11-20T18:20:28
C Added\ssupport\sfor\sproxy\sfile\slocking\sstyle\nAdded\spragma\ssupport\sfor\scontrolling\sproxy\sfile\slocking\nAdded\sfile\scontrol\saccess\sto\slast\serrno\sand\sproxy\slocking\nAdded\ssupport\sfor\sTMPDIR\senvironment\svariable\nExtended\sunit\stests\sto\scover\snew\sproxy\slocking\spragmas\sand\sfile\scontrol\sfeatures\s(CVS\s5934)
D 2008-11-21T00:10:35
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 0aa7bbe3be6acc4045706e3bb3fd0b8f38f4a3b5
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -137,7 +137,7 @@ F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4
F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c d12285d66df674c42f6f544a6f7c21bf1a954ee1
F src/os_unix.c 03c76b5269361adcd68cf9d6713181922535ac6e
F src/os_unix.c bdb0b66407141b7cd3520e92c685ea097b191c0e
F src/os_win.c 3dff41670fb9798a869c636626bb7d6d8b6a45bb
F src/pager.c db12a8333e54e7bbf62dc621ada5507adb3a6493
F src/pager.h a02ef8e6cc7e78b54874166e5ce786c9d4c489bf
@ -145,21 +145,21 @@ F src/parse.y 2c4758b4c5ead6de8cf7112f5a7cce7561d313fe
F src/pcache.c f3121a531745b20f5b824201eb63949a7e2959ac
F src/pcache.h f20c3e82dd6da622c3fe296170cb1801f9a2d75a
F src/pcache1.c 2453a3e925841fdb610f39bba24def8b2ad4a908
F src/pragma.c 0a5051029c5b687e2f2669d91aa3281ebcbe4fdb
F src/pragma.c 539e28c90e782fa909a3b3a6849d18a9eb11a548
F src/prepare.c fcadb25d2ad722d87103517333c825b56b79a770
F src/printf.c ce86aed93a704938ca4d0344aaa763271842a4b0
F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51
F src/resolve.c 4af5391d2b4c1d6c583a6805ac6660181de4545b
F src/select.c e01537d4d8b8b81a6507e07ebb17fc232dacdda7
F src/shell.c 650d1a87408682280d0e9d014d0d328c59c84b38
F src/sqlite.h.in e9a0aa2502dfe01bf166956051528f28871474c3
F src/sqlite.h.in b5d50f12fb9c7460a4ddfef8c1e799afaabefebf
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h beacd5768e55285097fbb419bcd741721b455003
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
F src/tclsqlite.c 96049bd454f1547abff0a57c45f0dfa57701e076
F src/test1.c 9b440b38e1710e9be1512c003fa141e0e3948e05
F src/test1.c d915e5cf26c5ba2a9778ad5b26cbaf97412b8b74
F src/test2.c 897528183edf2839c2a3c991d415905db56f1240
F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
@ -171,7 +171,7 @@ F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237
F src/test_async.c 45024094ed7cf780c5d5dccda645145f95cf78ef
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
F src/test_config.c bc71818f468494ff95ac1fe1f5906a21b25f937b
F src/test_config.c 47c66ced0faa6b18fbab72cbe77098ee04789722
F src/test_devsym.c 802d10e65b4217208cb47059b84adf46318bcdf4
F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
@ -293,11 +293,11 @@ F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
F test/exclusive.test 8d32ccf8eaf0260977dc8406bd70080ca2d7e6f8
F test/exclusive.test ecc64c394f5086d02159d8c0a82520f11420cf6a
F test/exclusive2.test 7d2b1c0370f1e1dac4a728bd653f2dea5100fcf6
F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
F test/expr.test 135ed46c049916688171e618c5c14312811618d4
F test/filectrl.test 524853082d5d7fb442599730ec3a0f3f84a3a936
F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8
F test/filefmt.test 053b622009fbbb74dd37921ffad374d852c13cd8
F test/fkey1.test c373e4f1ec43416957e0591c4a5cebb63b8a12e7
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@ -410,7 +410,8 @@ F test/lock.test 6825aea0b5885578b1b63a3b178803842c4ee9f1
F test/lock2.test 018b846f6f3b3b695fad07e317b7988442b556f4
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/lock4.test 09d97d52cae18fadfe631552af9880dac6b3ae90
F test/lock5.test 904c20aec51d5dbff0a3aec6a4d35c5ae0257449
F test/lock5.test a6eaac62eb14bc125f9cc0c2d06a80009fc67587
F test/lock6.test f4e9052b14da3bd6807a757d5aed15c17321031a
F test/lookaside.test e69f822f13745f1d5c445c6e30e30f059f30c8e5
F test/main.test 187a9a1b5248ed74a83838c581c15ec6023b555b
F test/malloc.test 248fc5e0be632d8db1d771ed5413a93c47212c5a
@ -433,7 +434,7 @@ F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
F test/mallocI.test 6e24fe6444bd2999ccc81f984977b44c0d6e5591
F test/mallocJ.test 44dfbbaca731cb933818ad300b4566265d652609
F test/malloc_common.tcl 984baeb6c6b185e798827d1187d426acc2bc4962
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/manydb.test b3d3bc4c25657e7f68d157f031eb4db7b3df0d3c
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
F test/memsubsys1.test bdc24a38d198679d777ca4efcc089fd3948567a6
@ -463,7 +464,7 @@ F test/pagesize.test 0d9ff3fedfce6e5ffe8fa7aca9b6d3433a2e843b
F test/pcache.test 515b4c26e9f57660357dfff5b6b697acac1abc5f
F test/pcache2.test 46efd980a89f737847b99327bda19e08fe11e402
F test/permutations.test 5308a94878efc81a8e8ce133926dfb2c53d19133
F test/pragma.test 165372b62391d233715cde82d99f34d306f9257f
F test/pragma.test 0f299601c3b15e8941eb48d2f7a43e6678e3f735
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
@ -491,7 +492,7 @@ F test/selectA.test 06d1032fa9009314c95394f2ca2e60d9f7ae8532
F test/selectB.test 31e81ac9af7d224850e0706350f070ecb92fcbc7
F test/selectC.test 44f4e1b2c86e40f8135294a826ec4142766e21c3
F test/server1.test f5b790d4c0498179151ca8a7715a65a7802c859c
F test/shared.test b9f3bbd3ba727c5f1f8c815b7d0199262aacf214
F test/shared.test 2f6c65de8123c130b92e4e18a516f669eaa02fea
F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4
F test/shared3.test 9c880afc081d797da514ef64bccf36f3fce2f09c
F test/shared4.test d0fadacb50bb6981b2fb9dc6d1da30fa1edddf83
@ -519,7 +520,7 @@ F test/tableapi.test 505031f15b18a750184d967d2c896cf88fcc969c
F test/tclsqlite.test 001682e3c188967fbd790c617991efadf9518386
F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1
F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
F test/tester.tcl 12fd8394caeb71f7d961707da8668756389bc9d3
F test/tester.tcl 66c41fc4d8a7f185d9abb21d68821c1f05e41f53
F test/thread001.test dda1d39cea954d7d43f520891d77a93d3325ab58
F test/thread002.test 84c03a9fc4f7a5f92eefe551266afa840c2eb6ae
F test/thread003.test e17754799649c2b732c295620dca041c32f01e16
@ -659,7 +660,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 00b68a1e3164fbf04dabb480c2037be45612b4e4
R 38e4d91990d6f71d4806b7fd8231a0a6
U drh
Z c8c595ff0394bbf0b4f1b46a403a8fd7
P eebacbc9d7d0625dfbe6367046fa4a0ca9c04e74
R 91b324303811443cc8a01d95fd1a412a
U aswift
Z 225056935d0aa6350680303c08feb50b

View File

@ -1 +1 @@
eebacbc9d7d0625dfbe6367046fa4a0ca9c04e74
b9bc36d3d5e35821ef69c0881a84c0afed253c9e

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.194 2008/11/17 19:18:55 danielk1977 Exp $
** $Id: pragma.c,v 1.195 2008/11/21 00:10:35 aswift Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -706,6 +706,48 @@ void sqlite3Pragma(
}
}else
/*
** PRAGMA [database.]lock_proxy_file
** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
**
** Return or set the value of the lock_proxy_file flag. Changing
** the value sets a specific file to be used for database access locks.
**
*/
if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
if( !zRight ){
Pager *pPager = sqlite3BtreePager(pDb->pBt);
char *proxy_file_path = NULL;
sqlite3_file *pFile = sqlite3PagerFile(pPager);
sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
&proxy_file_path);
if( proxy_file_path ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
"lock_proxy_file", SQLITE_STATIC);
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}
}else{
Pager *pPager = sqlite3BtreePager(pDb->pBt);
sqlite3_file *pFile = sqlite3PagerFile(pPager);
int res;
if( zRight[0] ){
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
zRight);
} else {
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
NULL);
}
if( res!=SQLITE_OK ){
sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
goto pragma_out;
}
}
}else
/*
** PRAGMA [database.]synchronous
** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL

View File

@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.415 2008/11/19 01:20:26 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.416 2008/11/21 00:10:35 aswift Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@ -507,6 +507,8 @@ int sqlite3_exec(
#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
/*
** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
@ -723,6 +725,9 @@ struct sqlite3_io_methods {
** is defined.
*/
#define SQLITE_FCNTL_LOCKSTATE 1
#define SQLITE_GET_LOCKPROXYFILE 2
#define SQLITE_SET_LOCKPROXYFILE 3
#define SQLITE_LAST_ERRNO 4
/*
** CAPI3REF: Mutex Handle {H17110} <S20130>

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.329 2008/10/30 15:03:16 drh Exp $
** $Id: test1.c,v 1.330 2008/11/21 00:10:35 aswift Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -4466,9 +4466,87 @@ static int file_control_test(
assert( rc==SQLITE_ERROR );
rc = sqlite3_file_control(db, "temp", -1, &iArg);
assert( rc==SQLITE_ERROR );
return TCL_OK;
}
/*
** tclcmd: file_control_lasterrno_test DB
**
** This TCL command runs the sqlite3_file_control interface and
** verifies correct operation of the SQLITE_LAST_ERRNO verb.
*/
static int file_control_lasterrno_test(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
int iArg = 0;
sqlite3 *db;
int rc;
if( objc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
rc = sqlite3_file_control(db, NULL, SQLITE_LAST_ERRNO, &iArg);
if( rc ) { Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR; }
if( iArg!=0 ) {
Tcl_AppendResult(interp, "Unexpected non-zero errno: ",
Tcl_GetStringFromObj(Tcl_NewIntObj(iArg), 0), " ", 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** tclcmd: file_control_lockproxy_test DB
**
** This TCL command runs the sqlite3_file_control interface and
** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
** SQLITE_SET_LOCKPROXYFILE verbs.
*/
static int file_control_lockproxy_test(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
int iArg = 0;
sqlite3 *db;
int rc;
if( objc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
#ifdef SQLITE_ENABLE_LOCKING_STYLE
{
char *proxyPath = "test.proxy";
char *testPath;
rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath);
if( rc ) { Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR; }
rc = sqlite3_file_control(db, NULL, SQLITE_GET_LOCKPROXYFILE, &testPath);
if( strncmp(proxyPath,testPath,11) ) {
Tcl_AppendResult(interp, "Lock proxy file did not match the previously assigned value", 0);
return TCL_ERROR;
}
if( rc ) { Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR; }
rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath);
if( rc ) { Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR; }
}
#endif
return TCL_OK;
}
/*
** tclcmd: sqlite3_vfs_list
**
@ -4640,6 +4718,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_open_file_count;
extern int sqlite3_sort_count;
extern int sqlite3_current_time;
extern int sqlite3_hostid_num;
extern int sqlite3_max_blobsize;
extern int sqlite3BtreeSharedCacheReport(void*,
Tcl_Interp*,int,Tcl_Obj*CONST*);
@ -4784,6 +4863,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "vfs_unregister_all", vfs_unregister_all, 0 },
{ "vfs_reregister_all", vfs_reregister_all, 0 },
{ "file_control_test", file_control_test, 0 },
{ "file_control_lasterrno_test", file_control_lasterrno_test, 0 },
{ "file_control_lockproxy_test", file_control_lockproxy_test, 0 },
{ "sqlite3_vfs_list", vfs_list, 0 },
/* Functions from os.h */
@ -4855,6 +4936,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_open_file_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_current_time",
(char*)&sqlite3_current_time, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_hostid_num",
(char*)&sqlite3_hostid_num, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite3_xferopt_count",
(char*)&sqlite3_xferopt_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite3_pager_readdb_count",

View File

@ -16,7 +16,7 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.42 2008/10/12 00:27:54 shane Exp $
** $Id: test_config.c,v 1.43 2008/11/21 00:10:35 aswift Exp $
*/
#include "sqliteLimit.h"
@ -392,6 +392,13 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
Tcl_SetVar2(interp, "sqlite_options", "schema_version", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_ENABLE_LOCKING_STYLE
Tcl_SetVar2(interp, "sqlite_options", "lock_proxy_pragmas", "1", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "lock_proxy_pragmas", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_SHARED_CACHE
Tcl_SetVar2(interp, "sqlite_options", "shared_cache", "0", TCL_GLOBAL_ONLY);
#else

View File

@ -12,7 +12,7 @@
# of these tests is exclusive access mode (i.e. the thing activated by
# "PRAGMA locking_mode = EXCLUSIVE").
#
# $Id: exclusive.test,v 1.9 2008/09/24 14:03:43 danielk1977 Exp $
# $Id: exclusive.test,v 1.10 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -402,6 +402,17 @@ do_test exclusive-4.5 {
db close
sqlite db test.db
# if we're using proxy locks, we use 3 filedescriptors for a db
# that is open but NOT writing changes, normally
# sqlite uses 1 (proxy locking adds the conch and the local lock)
set using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set using_proxy $value
}
set extrafds 0
if {$using_proxy!=0} {
set extrafds 2
}
do_test exclusive-5.0 {
execsql {
@ -414,6 +425,7 @@ do_test exclusive-5.0 {
do_test exclusive-5.1 {
# Three files are open: The db, journal and statement-journal.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {3}
do_test exclusive-5.2 {
execsql {
@ -421,6 +433,7 @@ do_test exclusive-5.2 {
}
# One file open: the db.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {1}
do_test exclusive-5.3 {
execsql {
@ -430,6 +443,7 @@ do_test exclusive-5.3 {
}
# Two files open: the db and journal.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {2}
do_test exclusive-5.4 {
execsql {
@ -437,6 +451,7 @@ do_test exclusive-5.4 {
}
# Three files are open: The db, journal and statement-journal.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {3}
do_test exclusive-5.5 {
execsql {
@ -444,6 +459,7 @@ do_test exclusive-5.5 {
}
# Three files are still open: The db, journal and statement-journal.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {3}
do_test exclusive-5.6 {
execsql {
@ -454,6 +470,7 @@ do_test exclusive-5.6 {
do_test exclusive-5.7 {
# Just the db open.
set sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds
} {1}
finish_test

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: filectrl.test,v 1.1 2008/01/22 14:50:17 drh Exp $
# $Id: filectrl.test,v 1.2 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -27,5 +27,15 @@ do_test filectrl-1.3 {
sqlite3 db :memory:
file_control_test db
} {}
do_test filectrl-1.4 {
sqlite3 db test.db
file_control_lasterrno_test db
} {}
do_test filectrl-1.5 {
db close
sqlite3 db test_control_lockproxy.db
file_control_lockproxy_test db
} {}
db close
file delete -force .test_control_lockproxy.db-conch test.proxy
finish_test

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is database locks.
#
# $Id: lock5.test,v 1.3 2008/09/24 09:12:47 danielk1977 Exp $
# $Id: lock5.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -25,6 +25,16 @@ if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
}
db close
ifcapable lock_proxy_pragmas {
set ::using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set ::using_proxy $value
}
# Disable the proxy locking for these tests
set env(SQLITE_FORCE_PROXY_LOCKING) "0"
}
do_test lock5-dotfile.1 {
sqlite3 db test.db -vfs unix-dotfile
execsql {
@ -173,4 +183,8 @@ do_test lock5-flock.X {
db2 close
} {}
ifcapable lock_proxy_pragmas {
set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy
}
finish_test

168
test/lock6.test Normal file
View File

@ -0,0 +1,168 @@
# 2008 October 6
#
# 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 database locks.
#
# $Id: lock6.test,v 1.1 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Launch another testfixture process to be controlled by this one. A
# channel name is returned that may be passed as the first argument to proc
# 'testfixture' to execute a command. The child testfixture process is shut
# down by closing the channel.
proc launch_testfixture {} {
set prg [info nameofexec]
if {$prg eq ""} {
set prg [file join . testfixture]
}
set chan [open "|$prg tf_main2.tcl" r+]
fconfigure $chan -buffering line
return $chan
}
# Execute a command in a child testfixture process, connected by two-way
# channel $chan. Return the result of the command, or an error message.
proc testfixture {chan cmd} {
puts $chan $cmd
puts $chan OVER
set r ""
while { 1 } {
set line [gets $chan]
if { $line == "OVER" } {
return $r
}
append r $line
}
}
# Write the main loop for the child testfixture processes into file
# tf_main2.tcl. The parent (this script) interacts with the child processes
# via a two way pipe. The parent writes a script to the stdin of the child
# process, followed by the word "OVER" on a line of its own. The child
# process evaluates the script and writes the results to stdout, followed
# by an "OVER" of its own.
set f [open tf_main2.tcl w]
puts $f {
set l [open log w]
set script ""
while {![eof stdin]} {
flush stdout
set line [gets stdin]
puts $l "READ $line"
if { $line == "OVER" } {
catch {eval $script} result
puts $result
puts $l "WRITE $result"
puts OVER
puts $l "WRITE OVER"
flush stdout
set script ""
} else {
append script $line
append script " ; "
}
}
close $l
}
close $f
ifcapable lock_proxy_pragmas {
set sqlite_hostid_num 1
set using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set using_proxy $value
}
# Test the lock_proxy_file pragmas.
#
set env(SQLITE_FORCE_PROXY_LOCKING) "1"
do_test lock6-1.1 {
set ::tf1 [launch_testfixture]
testfixture $::tf1 "set sqlite_pending_byte $::sqlite_pending_byte"
testfixture $::tf1 {
set sqlite_hostid_num 2
sqlite3 db test.db -key xyzzy
set lockpath [db eval {
PRAGMA lock_proxy_file=":auto:";
select * from sqlite_master;
PRAGMA lock_proxy_file;
}]
string match "*test.db:auto:" $lockpath
}
} {1}
set sqlite_hostid_num 3
do_test lock6-1.2 {
execsql {pragma lock_status}
} {main unlocked temp closed}
sqlite3_soft_heap_limit 0
do_test lock6-1.3 {
sqlite3 db test.db
catchsql {
select * from sqlite_master;
}
} {1 {database is locked}}
do_test lock6-1.4 {
set lockpath [execsql {
PRAGMA lock_proxy_file=":auto:";
PRAGMA lock_proxy_file;
} db]
set lockpath
} {{:auto: (not held)}}
do_test lock6-1.4.1 {
catchsql {
PRAGMA lock_proxy_file="notmine";
select * from sqlite_master;
} db
} {1 {database is locked}}
do_test lock6-1.4.2 {
execsql {
PRAGMA lock_proxy_file;
} db
} {notmine}
do_test lock6-1.5 {
testfixture $::tf1 {
db eval {
BEGIN;
SELECT * FROM sqlite_master;
}
}
} {}
catch {testfixture $::tf1 {db close}}
do_test lock6-1.6 {
execsql {
PRAGMA lock_proxy_file="mine";
select * from sqlite_master;
} db
} {}
catch {close $::tf1}
set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
set sqlite_hostid_num 0
sqlite3_soft_heap_limit $soft_limit
}
finish_test

View File

@ -13,12 +13,23 @@
# This file implements tests the ability of the library to open
# many different databases at the same time without leaking memory.
#
# $Id: manydb.test,v 1.3 2006/01/11 01:08:34 drh Exp $
# $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set N 300
# if we're using proxy locks, we use 5 filedescriptors for a db
# that is open and in the middle of writing changes, normally
# sqlite uses 3 (proxy locking adds the conch and the local lock)
set using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set using_proxy value
}
set num_fd_per_openwrite_db 3
if {$using_proxy>0} {
set num_fd_per_openwrite_db 5
}
# First test how many file descriptors are available for use. To open a
# database for writing SQLite requires 3 file descriptors (the database, the
@ -35,7 +46,7 @@ foreach fd $filehandles {
catch {
file delete -force testfile.1
}
set N [expr $i / 3]
set N [expr $i / $num_fd_per_openwrite_db]
# Create a bunch of random database names
#

View File

@ -12,7 +12,7 @@
#
# This file implements tests for the PRAGMA command.
#
# $Id: pragma.test,v 1.69 2008/10/23 05:45:07 danielk1977 Exp $
# $Id: pragma.test,v 1.70 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -34,6 +34,7 @@ source $testdir/tester.tcl
# pragma-14.*: Test the page_count pragma.
# pragma-15.*: Test that the value set using the cache_size pragma is not
# reset when the schema is reloaded.
# pragma-16.*: Test proxy locking
#
ifcapable !pragma {
@ -1252,4 +1253,134 @@ sqlite3 dbX :memory:
dbX eval {PRAGMA temp_store_directory = ""}
dbX close
ifcapable lock_proxy_pragmas {
set sqlite_hostid_num 1
set using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set using_proxy $value
}
# Test the lock_proxy_file pragmas.
#
db close
set env(SQLITE_FORCE_PROXY_LOCKING) "0"
sqlite3 db test.db
do_test pragma-16.1 {
execsql {
PRAGMA lock_proxy_file="mylittleproxy";
select * from sqlite_master;
}
execsql {
PRAGMA lock_proxy_file;
}
} {mylittleproxy}
do_test pragma-16.2 {
sqlite3 db2 test.db
execsql {
PRAGMA lock_proxy_file="mylittleproxy";
} db2
} {}
db2 close
do_test pragma-16.2.1 {
sqlite3 db2 test.db
execsql {
PRAGMA lock_proxy_file=":auto:";
select * from sqlite_master;
} db2
execsql {
PRAGMA lock_proxy_file;
} db2
} {mylittleproxy}
db2 close
do_test pragma-16.3 {
sqlite3 db2 test.db
execsql {
PRAGMA lock_proxy_file="myotherproxy";
} db2
catchsql {
select * from sqlite_master;
} db2
} {1 {database is locked}}
do_test pragma-16.4 {
db2 close
db close
sqlite3 db2 test.db
execsql {
PRAGMA lock_proxy_file="myoriginalproxy";
PRAGMA lock_proxy_file="myotherproxy";
PRAGMA lock_proxy_file;
} db2
} {myotherproxy}
db2 close
set env(SQLITE_FORCE_PROXY_LOCKING) "1"
do_test pragma-16.5 {
sqlite3 db2 test.db
execsql {
PRAGMA lock_proxy_file=":auto:";
PRAGMA lock_proxy_file;
} db2
} {myotherproxy}
do_test pragma-16.6 {
db2 close
sqlite3 db2 test2.db
set lockpath [execsql {
PRAGMA lock_proxy_file=":auto:";
PRAGMA lock_proxy_file;
} db2]
string match "*test2.db:auto:" $lockpath
} {1}
set sqlite_hostid_num 2
do_test pragma-16.7 {
sqlite3 db test2.db
execsql {
PRAGMA lock_proxy_file=":auto:";
}
catchsql {
select * from sqlite_master;
}
} {1 {database is locked}}
db close
do_test pragma-16.8 {
sqlite3 db test2.db
catchsql {
select * from sqlite_master;
}
} {1 {database is locked}}
db2 close
do_test pragma-16.8.1 {
execsql {
PRAGMA lock_proxy_file="yetanotherproxy";
PRAGMA lock_proxy_file;
}
} {yetanotherproxy}
do_test pragma-16.8.2 {
execsql {
create table mine(x);
}
} {}
db close
do_test pragma-16.9 {
sqlite3 db proxytest.db
set lockpath2 [execsql {
PRAGMA lock_proxy_file=":auto:";
PRAGMA lock_proxy_file;
} db]
string match "*proxytest.db:auto:" $lockpath2
} {1}
set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
set sqlite_hostid_num 0
}
finish_test

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: shared.test,v 1.34 2008/07/12 14:52:20 drh Exp $
# $Id: shared.test,v 1.35 2008/11/21 00:10:35 aswift Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -42,6 +42,20 @@ ifcapable autovacuum {
}
}
# if we're using proxy locks, we use 2 filedescriptors for a db
# that is open but NOT yet locked, after a lock is taken we'll have 3,
# normally sqlite uses 1 (proxy locking adds the conch and the local lock)
set using_proxy 0
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
set using_proxy $value
}
set extrafds_prelock 0
set extrafds_postlock 0
if {$using_proxy>0} {
set extrafds_prelock 1
set extrafds_postlock 2
}
# $av is currently 0 if this loop iteration is to test with auto-vacuum turned
# off, and 1 if it is turned on. Increment it so that (1 -> no auto-vacuum)
# and (2 -> auto-vacuum). The sole reason for this is so that it looks nicer
@ -74,6 +88,7 @@ do_test shared-$av.1.1 {
# opened.
sqlite3 db2 test.db
set ::sqlite_open_file_count
expr $sqlite_open_file_count-$extrafds_postlock
} {1}
do_test shared-$av.1.2 {
# Add a table and a single row of data via the first connection.
@ -154,6 +169,7 @@ do_test shared-$av.2.1 {
sqlite3 db3 TEST.DB
}
set ::sqlite_open_file_count
expr $sqlite_open_file_count-($extrafds_prelock+$extrafds_postlock)
} {2}
do_test shared-$av.2.2 {
# Start read transactions on db and db2 (the shared pager cache). Ensure
@ -284,14 +300,17 @@ sqlite3 db test.db
sqlite3 db2 test2.db
do_test shared-$av.4.1.1 {
set sqlite_open_file_count
expr $sqlite_open_file_count-($extrafds_prelock*2)
} {2}
do_test shared-$av.4.1.2 {
execsql {ATTACH 'test2.db' AS test2}
set sqlite_open_file_count
expr $sqlite_open_file_count-($extrafds_postlock*2)
} {2}
do_test shared-$av.4.1.3 {
execsql {ATTACH 'test.db' AS test} db2
set sqlite_open_file_count
expr $sqlite_open_file_count-($extrafds_postlock*2)
} {2}
# Sanity check: Create a table in ./test.db via handle db, and test that handle

View File

@ -11,7 +11,7 @@
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.134 2008/08/05 17:53:24 drh Exp $
# $Id: tester.tcl,v 1.135 2008/11/21 00:10:35 aswift Exp $
#
# What for user input before continuing. This gives an opportunity
@ -659,6 +659,7 @@ proc do_ioerr_test {testname args} {
do_test $testname.$n.1 {
set ::sqlite_io_error_pending 0
catch {db close}
catch {db2 close}
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
catch {file delete -force test2.db}