From f360396c47661cd814b1d9860ef004b3ac2891fc Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 7 Sep 2012 16:46:59 +0000 Subject: [PATCH 1/3] Add an experimental busy_timeout pragma to facilitate access to the sqlite3_busy_timeout() interfaces for programmers that are working from behind a language wrapper that does not expose that interface. FossilOrigin-Name: 22ebc668516bc3dd5782d6d3d42dc7fd2eed7d79 --- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- src/main.c | 1 + src/pragma.c | 16 ++++++++++++++++ test/lock.test | 23 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index deddb04066..fd801aab24 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\srepeating\scalls\sto\sthe\ssqlite3_trace()\scallback\swhen\sthe\ssame\sstatement\nis\sevaluted\smultiple\stimes\sby\ssqlite3_step()\sdue\sto\san\sSQLITE_SCHEMA\nreprepare. -D 2012-09-04T21:34:26.807 +C Add\san\sexperimental\sbusy_timeout\spragma\sto\sfacilitate\saccess\sto\sthe\nsqlite3_busy_timeout()\sinterfaces\sfor\sprogrammers\sthat\sare\sworking\sfrom\nbehind\sa\slanguage\swrapper\sthat\sdoes\snot\sexpose\sthat\sinterface. +D 2012-09-07T16:46:59.378 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -145,7 +145,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d -F src/main.c 02255cf1da50956c5427c469abddb15bccc4ba09 +F src/main.c 31af732aa4363e85816b09794429c79fe4baa3ac F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -170,7 +170,7 @@ F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c F src/pcache1.c 9fd22671c270b35131ef480bbc00392b8b5f8ab9 -F src/pragma.c 97f9357f0e7e5fb46a2519f14539550aa07db49f +F src/pragma.c e09950b9d0a35c1bf2329038c10f38589e754ae8 F src/prepare.c 33291b83cca285718048d219c67b8298501fa3a5 F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -571,7 +571,7 @@ F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e F test/loadext.test 2b5e249c51c986a5aff1f0950cf7ba30976c8f22 F test/loadext2.test 0bcaeb4d81cd5b6e883fdfea3c1bdbe1f173cbca -F test/lock.test db74fdf5a73bad29ab3d862ea78bf1068972cc1d +F test/lock.test 7e9eddd991b3af3a01caec2d9f030e0798deef74 F test/lock2.test 5242d8ac4e2d59c403aebff606af449b455aceff F test/lock3.test f271375930711ae044080f4fe6d6eda930870d00 F test/lock4.test e175ae13865bc87680607563bafba21f31a26f12 @@ -1014,7 +1014,10 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P c0d89d4a9752922f9e367362366efde4f1b06f2a -R f99616c13334ce584a8b1ebfcd476fa4 +P 39f763bfc04174ee0fe2cdf6a92b7c12f726bd1b +R 7a209eaa28bbe6aeaf699b5d2296eb6d +T *branch * busy-timeout-pragma +T *sym-busy-timeout-pragma * +T -sym-trunk * U drh -Z 2084e672100937502093a8dd98a48d0f +Z 3457f6820fedfafcfc1fb25157630cb3 diff --git a/manifest.uuid b/manifest.uuid index 28881c5c18..3068fe9942 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -39f763bfc04174ee0fe2cdf6a92b7c12f726bd1b \ No newline at end of file +22ebc668516bc3dd5782d6d3d42dc7fd2eed7d79 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 16294a6199..fa565982fa 100644 --- a/src/main.c +++ b/src/main.c @@ -1156,6 +1156,7 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){ db->busyTimeout = ms; sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); }else{ + db->busyTimeout = 0; sqlite3_busy_handler(db, 0, 0); } return SQLITE_OK; diff --git a/src/pragma.c b/src/pragma.c index a41e0e433f..c686265a22 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1536,6 +1536,22 @@ void sqlite3Pragma( sqlite3_db_release_memory(db); }else + /* + ** PRAGMA busy_timeout + ** PRAGMA busy_timeout = N + ** + ** Call sqlite3_busy_timeout(db, N). Return the current timeout value + ** if one is set. If the busy handler is not set to the default + ** busy callback, then the return value is undefined. A value of N + ** which is 0 or negative disables the busy handler. + */ + if( sqlite3StrICmp(zLeft, "busy_timeout")==0 ){ + if( zRight ){ + sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); + } + returnSingleInt(pParse, "timeout", db->busyTimeout); + }else + #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) /* ** Report the current state of file logs for all databases diff --git a/test/lock.test b/test/lock.test index 22f359c1a2..e3b1daad88 100644 --- a/test/lock.test +++ b/test/lock.test @@ -247,11 +247,34 @@ do_test lock-2.8 { execsql {UPDATE t1 SET a = 0 WHERE 0} catchsql {BEGIN EXCLUSIVE;} db2 } {1 {database is locked}} +do_test lock-2.8b { + db2 eval {PRAGMA busy_timeout} +} {400} do_test lock-2.9 { db2 timeout 0 execsql COMMIT } {} +do_test lock-2.9b { + db2 eval {PRAGMA busy_timeout} +} {0} integrity_check lock-2.10 +do_test lock-2.11 { + db2 eval {PRAGMA busy_timeout(400)} + execsql BEGIN + execsql {UPDATE t1 SET a = 0 WHERE 0} + catchsql {BEGIN EXCLUSIVE;} db2 +} {1 {database is locked}} +do_test lock-2.11b { + db2 eval {PRAGMA busy_timeout} +} {400} +do_test lock-2.12 { + db2 eval {PRAGMA busy_timeout(0)} + execsql COMMIT +} {} +do_test lock-2.11b { + db2 eval {PRAGMA busy_timeout} +} {0} +integrity_check lock-2.12 # Try to start two transactions in a row # From c0c7b5ee7448039476edb920c076dcb01f218fa8 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 7 Sep 2012 18:49:57 +0000 Subject: [PATCH 2/3] Have PRAGMA busy_timeout return 0 if the busy handler has been changed or cancelled. FossilOrigin-Name: 7be5bc36798d30f50658b70fc0bd31af897f3a87 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/main.c | 4 ++-- src/pragma.c | 6 +++--- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index fd801aab24..558095f7ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\sexperimental\sbusy_timeout\spragma\sto\sfacilitate\saccess\sto\sthe\nsqlite3_busy_timeout()\sinterfaces\sfor\sprogrammers\sthat\sare\sworking\sfrom\nbehind\sa\slanguage\swrapper\sthat\sdoes\snot\sexpose\sthat\sinterface. -D 2012-09-07T16:46:59.378 +C Have\sPRAGMA\sbusy_timeout\sreturn\s0\sif\sthe\sbusy\shandler\shas\sbeen\schanged\nor\scancelled. +D 2012-09-07T18:49:57.818 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -145,7 +145,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d -F src/main.c 31af732aa4363e85816b09794429c79fe4baa3ac +F src/main.c 0b321fc873ff2c09b996dea9f74443e4cd9ae28d F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -170,7 +170,7 @@ F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c F src/pcache1.c 9fd22671c270b35131ef480bbc00392b8b5f8ab9 -F src/pragma.c e09950b9d0a35c1bf2329038c10f38589e754ae8 +F src/pragma.c 360ac85ad9bfbab2302e8b7ba524af842f497cef F src/prepare.c 33291b83cca285718048d219c67b8298501fa3a5 F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -1014,10 +1014,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 39f763bfc04174ee0fe2cdf6a92b7c12f726bd1b -R 7a209eaa28bbe6aeaf699b5d2296eb6d -T *branch * busy-timeout-pragma -T *sym-busy-timeout-pragma * -T -sym-trunk * +P 22ebc668516bc3dd5782d6d3d42dc7fd2eed7d79 +R 123b3377f1885f394458b43e10ba3388 U drh -Z 3457f6820fedfafcfc1fb25157630cb3 +Z ffcbc3d2ba50a5d9635e1edbbde2b179 diff --git a/manifest.uuid b/manifest.uuid index 3068fe9942..c4246a80ba 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -22ebc668516bc3dd5782d6d3d42dc7fd2eed7d79 \ No newline at end of file +7be5bc36798d30f50658b70fc0bd31af897f3a87 \ No newline at end of file diff --git a/src/main.c b/src/main.c index fa565982fa..745122559d 100644 --- a/src/main.c +++ b/src/main.c @@ -1116,6 +1116,7 @@ int sqlite3_busy_handler( db->busyHandler.xFunc = xBusy; db->busyHandler.pArg = pArg; db->busyHandler.nBusy = 0; + db->busyTimeout = 0; sqlite3_mutex_leave(db->mutex); return SQLITE_OK; } @@ -1153,10 +1154,9 @@ void sqlite3_progress_handler( */ int sqlite3_busy_timeout(sqlite3 *db, int ms){ if( ms>0 ){ - db->busyTimeout = ms; sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); + db->busyTimeout = ms; }else{ - db->busyTimeout = 0; sqlite3_busy_handler(db, 0, 0); } return SQLITE_OK; diff --git a/src/pragma.c b/src/pragma.c index c686265a22..57978c22cc 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1541,9 +1541,9 @@ void sqlite3Pragma( ** PRAGMA busy_timeout = N ** ** Call sqlite3_busy_timeout(db, N). Return the current timeout value - ** if one is set. If the busy handler is not set to the default - ** busy callback, then the return value is undefined. A value of N - ** which is 0 or negative disables the busy handler. + ** if one is set. If no busy handler or a different busy handler is set + ** then 0 is returned. Setting the busy_timeout to 0 or negative + ** disables the timeout. */ if( sqlite3StrICmp(zLeft, "busy_timeout")==0 ){ if( zRight ){ From 50610df8ae1a03d971d732685549443c6a6c26d3 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 7 Sep 2012 20:10:30 +0000 Subject: [PATCH 3/3] Correct two test names to make them unique. FossilOrigin-Name: 43e474d3e9364e6ed417db06e98faa3e5bc2eb26 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/lock.test | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 558095f7ba..4ffa80d78b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sPRAGMA\sbusy_timeout\sreturn\s0\sif\sthe\sbusy\shandler\shas\sbeen\schanged\nor\scancelled. -D 2012-09-07T18:49:57.818 +C Correct\stwo\stest\snames\sto\smake\sthem\sunique. +D 2012-09-07T20:10:30.599 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -571,7 +571,7 @@ F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e F test/loadext.test 2b5e249c51c986a5aff1f0950cf7ba30976c8f22 F test/loadext2.test 0bcaeb4d81cd5b6e883fdfea3c1bdbe1f173cbca -F test/lock.test 7e9eddd991b3af3a01caec2d9f030e0798deef74 +F test/lock.test 87af515b0c4cf928576d0f89946d67d7c265dfb4 F test/lock2.test 5242d8ac4e2d59c403aebff606af449b455aceff F test/lock3.test f271375930711ae044080f4fe6d6eda930870d00 F test/lock4.test e175ae13865bc87680607563bafba21f31a26f12 @@ -1014,7 +1014,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 22ebc668516bc3dd5782d6d3d42dc7fd2eed7d79 -R 123b3377f1885f394458b43e10ba3388 -U drh -Z ffcbc3d2ba50a5d9635e1edbbde2b179 +P 7be5bc36798d30f50658b70fc0bd31af897f3a87 +R 0d92940b96f13ff3dc822c3dd51f8373 +U mistachkin +Z ac2b57c54956518a08fcca693b6facfe diff --git a/manifest.uuid b/manifest.uuid index c4246a80ba..b0647f7277 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7be5bc36798d30f50658b70fc0bd31af897f3a87 \ No newline at end of file +43e474d3e9364e6ed417db06e98faa3e5bc2eb26 \ No newline at end of file diff --git a/test/lock.test b/test/lock.test index e3b1daad88..6ec85eea3c 100644 --- a/test/lock.test +++ b/test/lock.test @@ -271,10 +271,10 @@ do_test lock-2.12 { db2 eval {PRAGMA busy_timeout(0)} execsql COMMIT } {} -do_test lock-2.11b { +do_test lock-2.12b { db2 eval {PRAGMA busy_timeout} } {0} -integrity_check lock-2.12 +integrity_check lock-2.13 # Try to start two transactions in a row #