From deed33aec73ebdd869ff5fc6dcb9a3bd5a039a7f Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 6 Nov 2016 20:46:27 +0900 Subject: [PATCH] cancel --- sqlite3.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sqlite3.go b/sqlite3.go index c1c42f0..ac069e3 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -817,6 +817,17 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result C.sqlite3_clear_bindings(s.s) return nil, err } + + done := make(chan struct{}) + defer close(done) + go func() { + select { + case <-ctx.Done(): + C.sqlite3_interrupt(s.c.db) + case <-done: + } + }() + var rowid, changes C.longlong rv := C._sqlite3_step(s.s, &rowid, &changes) if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE { @@ -825,6 +836,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result C.sqlite3_clear_bindings(s.s) return nil, err } + return &SQLiteResult{int64(rowid), int64(changes)}, nil }