More consistent interrupts.

This commit is contained in:
Nuno Cruces
2024-10-08 16:38:57 +01:00
parent cc7bacfb9c
commit e524fb185d
3 changed files with 7 additions and 1 deletions

View File

@@ -253,6 +253,7 @@ func (b *Blob) Seek(offset int64, whence int) (int64, error) {
// //
// https://sqlite.org/c3ref/blob_reopen.html // https://sqlite.org/c3ref/blob_reopen.html
func (b *Blob) Reopen(row int64) error { func (b *Blob) Reopen(row int64) error {
b.c.checkInterrupt(b.c.handle)
err := b.c.error(b.c.call("sqlite3_blob_reopen", uint64(b.handle), uint64(row))) err := b.c.error(b.c.call("sqlite3_blob_reopen", uint64(b.handle), uint64(row)))
b.bytes = int64(b.c.call("sqlite3_blob_bytes", uint64(b.handle))) b.bytes = int64(b.c.call("sqlite3_blob_bytes", uint64(b.handle)))
b.offset = 0 b.offset = 0

View File

@@ -204,6 +204,7 @@ func (c *Conn) PrepareFlags(sql string, flags PrepareFlag) (stmt *Stmt, tail str
tailPtr := c.arena.new(ptrlen) tailPtr := c.arena.new(ptrlen)
sqlPtr := c.arena.string(sql) sqlPtr := c.arena.string(sql)
c.checkInterrupt(c.handle)
r := c.call("sqlite3_prepare_v3", uint64(c.handle), r := c.call("sqlite3_prepare_v3", uint64(c.handle),
uint64(sqlPtr), uint64(len(sql)+1), uint64(flags), uint64(sqlPtr), uint64(len(sql)+1), uint64(flags),
uint64(stmtPtr), uint64(tailPtr)) uint64(stmtPtr), uint64(tailPtr))

View File

@@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"time"
"github.com/ncruces/go-sqlite3" "github.com/ncruces/go-sqlite3"
_ "github.com/ncruces/go-sqlite3/embed" _ "github.com/ncruces/go-sqlite3/embed"
@@ -148,7 +149,10 @@ func TestConn_SetInterrupt(t *testing.T) {
defer stmt.Close() defer stmt.Close()
db.SetInterrupt(ctx) db.SetInterrupt(ctx)
go cancel() go func() {
time.Sleep(time.Millisecond)
cancel()
}()
// Interrupting works. // Interrupting works.
err = stmt.Exec() err = stmt.Exec()