Skip to content

Commit

Permalink
libsql-sqlite: Add libsql_stmt_interrupt() API
Browse files Browse the repository at this point in the history
This adds an API for interrupting a specific statement instead of all
pending operations like `sqlite3_interrupt()` does.
  • Loading branch information
penberg committed Dec 20, 2024
1 parent 58b016a commit 6249bea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libsql-sqlite3/src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5390,6 +5390,8 @@ int sqlite3_finalize(sqlite3_stmt *pStmt);
int sqlite3_reset(sqlite3_stmt *pStmt);


void libsql_stmt_interrupt(sqlite3_stmt *stmt);

/*
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
Expand Down
1 change: 1 addition & 0 deletions libsql-sqlite3/src/vdbeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ struct Vdbe {
int nScan; /* Entries in aScan[] */
ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
#endif
u8 isInterrupted; /* True if the statement has been interrupted */
};

void libsql_inc_row_read(Vdbe *p, int count);
Expand Down
15 changes: 15 additions & 0 deletions libsql-sqlite3/src/vdbeapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,18 @@ static int sqlite3Step(Vdbe *p){
return (rc&db->errMask);
}

/*
** Interrupt the statement.
*/
void libsql_stmt_interrupt(sqlite3_stmt *pStmt){
Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
if( vdbeSafetyNotNull(v) ){
(void)SQLITE_MISUSE_BKPT;
return;
}
v->isInterrupted = 1;
}

/*
** This is the top-level implementation of sqlite3_step(). Call
** sqlite3Step() to do most of the work. If a schema error occurs,
Expand All @@ -902,6 +914,9 @@ int sqlite3_step(sqlite3_stmt *pStmt){
if( vdbeSafetyNotNull(v) ){
return SQLITE_MISUSE_BKPT;
}
if( v->isInterrupted ){
return SQLITE_INTERRUPT;
}
db = v->db;
sqlite3_mutex_enter(db->mutex);
while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
Expand Down

0 comments on commit 6249bea

Please sign in to comment.