Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsql-sqlite: Add libsql_stmt_interrupt() API #1888

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5779,6 +5779,8 @@ SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);


SQLITE_API void libsql_stmt_interrupt(sqlite3_stmt *stmt);

/*
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
Expand Down Expand Up @@ -24195,6 +24197,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 Expand Up @@ -67644,9 +67647,11 @@ static int walCheckpoint(
if (xCb) {
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
}
i64 szDb = pWal->hdr.nPage*(i64)szPage;
testcase( IS_BIG_INT(szDb) );
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
if( rc==SQLITE_OK ){
i64 szDb = pWal->hdr.nPage*(i64)szPage;
testcase( IS_BIG_INT(szDb) );
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
}
if( rc==SQLITE_OK ){
rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
}
Expand Down Expand Up @@ -89473,6 +89478,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;

/* Save profiling information from this VDBE run.
*/
Expand Down Expand Up @@ -92277,6 +92283,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 @@ -92291,6 +92309,9 @@ SQLITE_API 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
19 changes: 7 additions & 12 deletions libsql-ffi/bundled/bindings/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ extern "C" {
extern "C" {
pub fn sqlite3_vmprintf(
arg1: *const ::std::os::raw::c_char,
arg2: *mut __va_list_tag,
arg2: va_list,
) -> *mut ::std::os::raw::c_char;
}
extern "C" {
Expand All @@ -956,7 +956,7 @@ extern "C" {
arg1: ::std::os::raw::c_int,
arg2: *mut ::std::os::raw::c_char,
arg3: *const ::std::os::raw::c_char,
arg4: *mut __va_list_tag,
arg4: va_list,
) -> *mut ::std::os::raw::c_char;
}
extern "C" {
Expand Down Expand Up @@ -1538,6 +1538,9 @@ extern "C" {
extern "C" {
pub fn sqlite3_reset(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn libsql_stmt_interrupt(stmt: *mut sqlite3_stmt);
}
extern "C" {
pub fn sqlite3_create_function(
db: *mut sqlite3,
Expand Down Expand Up @@ -2503,7 +2506,7 @@ extern "C" {
pub fn sqlite3_str_vappendf(
arg1: *mut sqlite3_str,
zFormat: *const ::std::os::raw::c_char,
arg2: *mut __va_list_tag,
arg2: va_list,
);
}
extern "C" {
Expand Down Expand Up @@ -3570,12 +3573,4 @@ extern "C" {
extern "C" {
pub static sqlite3_wal_manager: libsql_wal_manager;
}
pub type __builtin_va_list = [__va_list_tag; 1usize];
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __va_list_tag {
pub gp_offset: ::std::os::raw::c_uint,
pub fp_offset: ::std::os::raw::c_uint,
pub overflow_arg_area: *mut ::std::os::raw::c_void,
pub reg_save_area: *mut ::std::os::raw::c_void,
}
pub type __builtin_va_list = *mut ::std::os::raw::c_char;
19 changes: 19 additions & 0 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5779,6 +5779,8 @@ SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);


SQLITE_API void libsql_stmt_interrupt(sqlite3_stmt *stmt);

/*
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
Expand Down Expand Up @@ -24195,6 +24197,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 Expand Up @@ -89475,6 +89478,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;

/* Save profiling information from this VDBE run.
*/
Expand Down Expand Up @@ -92279,6 +92283,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 @@ -92293,6 +92309,9 @@ SQLITE_API 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
2 changes: 2 additions & 0 deletions libsql-ffi/bundled/src/sqlite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -5390,6 +5390,8 @@ SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);


SQLITE_API void libsql_stmt_interrupt(sqlite3_stmt *stmt);

/*
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
Expand Down
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
1 change: 1 addition & 0 deletions libsql-sqlite3/src/vdbeaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,7 @@ int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;

/* Save profiling information from this VDBE run.
*/
Expand Down
Loading