Skip to content

Commit 2c4c2d8

Browse files
committedJan 29, 2025
libsql-sqlite: Add libsql_stmt_interrupt() API
This adds an API for interrupting a specific statement instead of all pending operations like `sqlite3_interrupt()` does.
1 parent 1e6af39 commit 2c4c2d8

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎libsql-sqlite3/src/sqlite.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -5390,6 +5390,8 @@ int sqlite3_finalize(sqlite3_stmt *pStmt);
53905390
int sqlite3_reset(sqlite3_stmt *pStmt);
53915391

53925392

5393+
void libsql_stmt_interrupt(sqlite3_stmt *stmt);
5394+
53935395
/*
53945396
** CAPI3REF: Create Or Redefine SQL Functions
53955397
** KEYWORDS: {function creation routines}

‎libsql-sqlite3/src/vdbeInt.h

+1
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ struct Vdbe {
528528
int nScan; /* Entries in aScan[] */
529529
ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
530530
#endif
531+
u8 isInterrupted; /* True if the statement has been interrupted */
531532
};
532533

533534
void libsql_inc_row_read(Vdbe *p, int count);

‎libsql-sqlite3/src/vdbeapi.c

+15
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,18 @@ static int sqlite3Step(Vdbe *p){
888888
return (rc&db->errMask);
889889
}
890890

891+
/*
892+
** Interrupt the statement.
893+
*/
894+
void libsql_stmt_interrupt(sqlite3_stmt *pStmt){
895+
Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
896+
if( vdbeSafetyNotNull(v) ){
897+
(void)SQLITE_MISUSE_BKPT;
898+
return;
899+
}
900+
v->isInterrupted = 1;
901+
}
902+
891903
/*
892904
** This is the top-level implementation of sqlite3_step(). Call
893905
** sqlite3Step() to do most of the work. If a schema error occurs,
@@ -902,6 +914,9 @@ int sqlite3_step(sqlite3_stmt *pStmt){
902914
if( vdbeSafetyNotNull(v) ){
903915
return SQLITE_MISUSE_BKPT;
904916
}
917+
if( v->isInterrupted ){
918+
return SQLITE_INTERRUPT;
919+
}
905920
db = v->db;
906921
sqlite3_mutex_enter(db->mutex);
907922
while( (rc = sqlite3Step(v))==SQLITE_SCHEMA

0 commit comments

Comments
 (0)