diff --git a/libsql-sqlite3/src/sqlite.h.in b/libsql-sqlite3/src/sqlite.h.in index dab6c31db4..5fbec4caca 100644 --- a/libsql-sqlite3/src/sqlite.h.in +++ b/libsql-sqlite3/src/sqlite.h.in @@ -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} diff --git a/libsql-sqlite3/src/vdbeInt.h b/libsql-sqlite3/src/vdbeInt.h index 1e6fb147ca..afef44b0e4 100644 --- a/libsql-sqlite3/src/vdbeInt.h +++ b/libsql-sqlite3/src/vdbeInt.h @@ -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); diff --git a/libsql-sqlite3/src/vdbeapi.c b/libsql-sqlite3/src/vdbeapi.c index cc3e457c91..601b302ff1 100644 --- a/libsql-sqlite3/src/vdbeapi.c +++ b/libsql-sqlite3/src/vdbeapi.c @@ -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, @@ -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