]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a new sqlite3_is_interrupted() interface that can be used by long-running
authordrh <>
Wed, 11 Jan 2023 00:27:06 +0000 (00:27 +0000)
committerdrh <>
Wed, 11 Jan 2023 00:27:06 +0000 (00:27 +0000)
app-defined functions and similar to see if they need to exit early due to
an sqlite3_interrupt() call.

FossilOrigin-Name: d030f341369b7f32789cbcf3d0ad9a2ac5cad99a56dac7dfe68b7f06dc339b17

manifest
manifest.uuid
src/loadext.c
src/main.c
src/sqlite.h.in
src/sqlite3ext.h
src/test1.c
test/interrupt.test

index f8c1c43d40bd5e01114e8510545ffcfac64c4f95..655be1900afabf49e5acd0c68cdb37e33c23b7d2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C When\scomputing\sthe\sdatatypes\sfor\scolumns\sin\sa\sview,\suse\sthe\ssame\sdatatype\sname\nas\sthe\sunderlying\stable\sif\ssuch\sis\savailable\sand\sis\sconsistent\swith\nthe\scomputed\saffinity\sof\sthe\scolumn.\n[forum:/forumpost/7fb1fe9dcf310ef5|Forum\sthread\s7fb1fe9dcf310ef5].
-D 2023-01-10T19:57:26.448
+C Add\sa\snew\ssqlite3_is_interrupted()\sinterface\sthat\scan\sbe\sused\sby\slong-running\napp-defined\sfunctions\sand\ssimilar\sto\ssee\sif\sthey\sneed\sto\sexit\searly\sdue\sto\nan\ssqlite3_interrupt()\scall.
+D 2023-01-11T00:27:06.320
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -607,8 +607,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c 1b11a2e33ee52db93c02fddac67e39d00161d61b69fac2675b82f2aa68c1b61c
 F src/json.c 7749b98c62f691697c7ee536b570c744c0583cab4a89200fdd0fc2aa8cc8cbd6
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
-F src/loadext.c 25663175950c5c4404b9377840b7b4c6fe5c53b415caf43634c62f442c02a9a7
-F src/main.c fd4f7da9a7ba04e6afe834748a6ee78f699f7ba28570bb2cdb028753140d93f9
+F src/loadext.c b04eb648cedc45efe4298e1ef439ac4f0096ae27b5f01accb0a1f49d57789128
+F src/main.c f5ed7b748d7e54b96ac577a9d87af9461f13f092bbe684d473448010333402dc
 F src/malloc.c 47b82c5daad557d9b963e3873e99c22570fb470719082c6658bf64e3012f7d23
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
@@ -647,15 +647,15 @@ F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 146222acbf9ea4e7f99c45a9e3cb4a0ba7e02c4f0df5186094ea1f9ea9907a02
 F src/shell.c.in f7c75d1a9f900516e40f17f040668d5797592344bd88cff7ee7df586de6893c6
-F src/sqlite.h.in 317be795a707c93c03810ba362edb20b49c4ea61b5f1777eeb6557fcaac4a688
+F src/sqlite.h.in 231d505c86ac4688b82259529273fe5fb2cce86cb80ea50628ff776113b5c706
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
-F src/sqlite3ext.h c4b9fa7a7e2bcdf850cfeb4b8a91d5ec47b7a00033bc996fd2ee96cbf2741f5f
+F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
 F src/sqliteInt.h 079ccd9c161f4b74967188fd6321810159fdc4c32371b68559719828fac20f43
 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
 F src/tclsqlite.c 4e64ba300a5a26e0f1170e09032429faeb65e45e8f3d1a7833e8edb69fc2979e
-F src/test1.c 98f4a4525e10b0df164ba7f33950824348bb29fd582101e0f93b1af72f493154
+F src/test1.c 39c13c25f5c4e75a07cb6bd34cfc1b8aa97ecc6f80f08953fa164db7e92ce71e
 F src/test2.c 827446e259a3b7ab949da1542953edda7b5117982576d3e6f1c24a0dd20a5cef
 F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
 F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664
@@ -1228,7 +1228,7 @@ F test/insertfault.test ac63d14ea3b49c573673a572f4014b9117383a03e497c58f308b5c77
 F test/instr.test 107df2b9b74a4b59315916b575590a08f2a714de0754abe541f10a0971d0a2a4
 F test/instrfault.test 95e28efade652e6d51ae11b377088fe523a581a07ec428009e152a4dd0e0f44c
 F test/intarray.test bb976b0b3df0ebb6a2eddfb61768280440e672beba5460ed49679ea984ccf440
-F test/interrupt.test 16ea879ec728cb76414c148c5f24afd5d1f91054
+F test/interrupt.test ac1ef50ec9ab8e4f0e17c47629f82539d4b22558904e321ed5abea2e6187da7a
 F test/interrupt2.test e4408ca770a6feafbadb0801e54a0dcd1a8d108d
 F test/intpkey.test aee694afed1a65c86c4e69ad030224b3fc268113d00685234d40079fca16bad3
 F test/intreal.test 68829a8bb073ee1610ca3f8f9e0f99b0371fb36e0fa64862dd5ced4ef03c2343
@@ -2068,8 +2068,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b829dd1b976454619ca04c69aec5ebb5a2286772f4267b82ab2ea5fdb81ccd41
-R 80d188f8438144856a5716ba93918203
+P 497a98363fd1ed079544620ec5d0883f987ed03013131542741c93d7568e8568
+R e84e9815577445777c418ec27de1611c
 U drh
-Z 9fbf6186a1b4571002919f577b2c4f18
+Z e942c6a2be2eab85b4349c82956d7559
 # Remove this line to create a well-formed Fossil manifest.
index 1b851e693b4713265d0b04d5574a9b9bdb839679..016874967dc91accb3611ee59d1f79f4e70f3507 100644 (file)
@@ -1 +1 @@
-497a98363fd1ed079544620ec5d0883f987ed03013131542741c93d7568e8568
\ No newline at end of file
+d030f341369b7f32789cbcf3d0ad9a2ac5cad99a56dac7dfe68b7f06dc339b17
\ No newline at end of file
index c14338f8b4311ec35028e367ec6fdcef1cdf07ca..40bde9ce80aede0e293e723d17c57474184d5186 100644 (file)
@@ -510,7 +510,9 @@ static const sqlite3_api_routines sqlite3Apis = {
 #endif
   sqlite3_db_name,
   /* Version 3.40.0 and later */
-  sqlite3_value_encoding
+  sqlite3_value_encoding,
+  /* Version 3.41.0 and later */
+  sqlite3_is_interrupted
 };
 
 /* True if x is the directory separator character
index e22ff96dec371b62a9efab46242ee9476185cca1..eaecb56df9f3beee4afafe530ee4600d920fbce7 100644 (file)
@@ -1796,7 +1796,9 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
 */
 void sqlite3_interrupt(sqlite3 *db){
 #ifdef SQLITE_ENABLE_API_ARMOR
-  if( !sqlite3SafetyCheckOk(db) && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) ){
+  if( !sqlite3SafetyCheckOk(db)
+   && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
+  ){
     (void)SQLITE_MISUSE_BKPT;
     return;
   }
@@ -1804,6 +1806,21 @@ void sqlite3_interrupt(sqlite3 *db){
   AtomicStore(&db->u1.isInterrupted, 1);
 }
 
+/*
+** Return true or false depending on whether or not an interrupt is
+** pending on connection db.
+*/
+int sqlite3_is_interrupted(sqlite3 *db){
+#ifdef SQLITE_ENABLE_API_ARMOR
+  if( !sqlite3SafetyCheckOk(db)
+   && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
+  ){
+    (void)SQLITE_MISUSE_BKPT;
+    return 0;
+  }
+#endif
+  return AtomicLoad(&db->u1.isInterrupted)!=0;
+}
 
 /*
 ** This function is exactly the same as sqlite3_create_function(), except
index 55cf468e3c4240d8fe2e801a14e98a60f2d506cd..57bbdb7a1dedf0f679761a28c45ef194a5993fed 100644 (file)
@@ -2679,8 +2679,12 @@ sqlite3_int64 sqlite3_total_changes64(sqlite3*);
 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
 ** SQL statements is a no-op and has no effect on SQL statements
 ** that are started after the sqlite3_interrupt() call returns.
+**
+** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
+** or not an interrupt is currently in effect for [database connection] D.
 */
 void sqlite3_interrupt(sqlite3*);
+int sqlite3_is_interrupted(sqlite3*);
 
 /*
 ** CAPI3REF: Determine If An SQL Statement Is Complete
index 79702d7b21e3aadf11844809e74dba71cdbdcbc7..19e030028adfeb18e524dc4ad7cae3f294a8db81 100644 (file)
@@ -359,6 +359,8 @@ struct sqlite3_api_routines {
   const char *(*db_name)(sqlite3*,int);
   /* Version 3.40.0 and later */
   int (*value_encoding)(sqlite3_value*);
+  /* Version 3.41.0 and later */
+  int (*is_interrupted)(sqlite3*);
 };
 
 /*
@@ -685,6 +687,8 @@ typedef int (*sqlite3_loadext_entry)(
 #define sqlite3_db_name                sqlite3_api->db_name
 /* Version 3.40.0 and later */
 #define sqlite3_value_encoding         sqlite3_api->value_encoding
+/* Version 3.41.0 and later */
+#define sqlite3_is_interrupted         sqlite3_api->is_interrupted
 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
 
 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
index a314e90d848b70e451c10947ec6c85291999011b..dda77a90a50ce4e1b2f404722c02aa01315a7c12 100644 (file)
@@ -5537,7 +5537,6 @@ static int SQLITE_TCLAPI test_stmt_int(
   return TCL_OK;
 }
 
-
 /*
 ** Usage:  sqlite3_interrupt  DB 
 **
@@ -5559,6 +5558,29 @@ static int SQLITE_TCLAPI test_interrupt(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite3_is_interrupted  DB 
+**
+** return true if an interrupt is current in effect on DB
+*/
+static int SQLITE_TCLAPI test_is_interrupted(
+  void * clientData,
+  Tcl_Interp *interp,
+  int argc,
+  char **argv
+){
+  sqlite3 *db;
+  int rc;
+  if( argc!=2 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0);
+    return TCL_ERROR;
+  }
+  if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
+  rc = sqlite3_is_interrupted(db);
+  Tcl_AppendResult(interp, rc ? "1" : "0", (void*)0);
+  return TCL_OK;
+}
+
 /*
 ** Usage: sqlite_delete_function DB function-name
 **
@@ -8631,6 +8653,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_key",                   (Tcl_CmdProc*)test_key              },
      { "sqlite3_rekey",                 (Tcl_CmdProc*)test_rekey            },
      { "sqlite3_interrupt",             (Tcl_CmdProc*)test_interrupt        },
+     { "sqlite3_is_interrupted",        (Tcl_CmdProc*)test_is_interrupted   },
      { "sqlite_delete_function",        (Tcl_CmdProc*)delete_function       },
      { "sqlite_delete_collation",       (Tcl_CmdProc*)delete_collation      },
      { "sqlite3_get_autocommit",        (Tcl_CmdProc*)get_autocommit        },
index 8774aee860c246c1424136f2531f1b4d0a135324..23d986987432c76f68a14146613d9bab75361ede 100644 (file)
@@ -94,14 +94,28 @@ ifcapable {vacuum && !default_autovacuum} {
   } 1
 }
 ifcapable {explain} {
-  do_test interrupt-2.5 {
+  do_test interrupt-2.5.1 {
+    sqlite3_is_interrupted $DB
+  } {0}
+  do_test interrupt-2.5.2 {
+    unset -nocomplain ::interrupt_count
+    set ::interrupt_count 0
     set sql {EXPLAIN SELECT max(a,b), a, b FROM t1}
     execsql $sql
-    set rc [catch {db eval $sql {sqlite3_interrupt $DB}} msg]
+    set rc [catch {db eval $sql {
+      sqlite3_interrupt $DB;
+      incr ::interrupt_count [sqlite3_is_interrupted $DB];
+    }} msg]
     lappend rc $msg
   } {1 interrupted}
+  do_test interrupt-2.5.3 {
+    set ::interrupt_count
+  } {1}
 }
 integrity_check interrupt-2.6
+do_test interrupt-2.7 {
+  sqlite3_is_interrupted $DB
+} {0}
 
 # Ticket #594.  If an interrupt occurs in the middle of a transaction
 # and that transaction is later rolled back, the internal schema tables do