From 04231da4ed67c36cac0608d38a200b2c0f4994aa Mon Sep 17 00:00:00 2001 From: Marc Boeker Date: Fri, 12 Jan 2024 12:45:28 +0100 Subject: [PATCH] Switch to duckdb_execute_pending --- duckdb_test.go | 1 - statement.go | 25 ++++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/duckdb_test.go b/duckdb_test.go index 1f37c31e..d9303973 100644 --- a/duckdb_test.go +++ b/duckdb_test.go @@ -1101,7 +1101,6 @@ func TestParquetExtension(t *testing.T) { } func TestQueryTimeout(t *testing.T) { - t.Skip("TODO: fix blocking in duckdb_pending_execute_task first.") db := openDB(t) defer db.Close() diff --git a/statement.go b/statement.go index ce0af208..5756410b 100644 --- a/statement.go +++ b/statement.go @@ -203,28 +203,27 @@ func (s *stmt) execute(ctx context.Context, args []driver.NamedValue) (*C.duckdb } defer C.duckdb_destroy_pending(&pendingRes) - for { + done := make(chan bool) + defer close(done) + + go func() { select { // if context is cancelled or deadline exceeded, don't execute further case <-ctx.Done(): // also need to interrupt to cancel the query C.duckdb_interrupt(*s.c.con) - return nil, ctx.Err() - default: - // continue - } - state := C.duckdb_pending_execute_task(pendingRes) - if state == C.DUCKDB_PENDING_ERROR { - dbErr := C.GoString(C.duckdb_pending_error(pendingRes)) - return nil, errors.New(dbErr) - } - if C.duckdb_pending_execution_is_finished(state) { - break + return + case <-done: + return } - } + }() var res C.duckdb_result if state := C.duckdb_execute_pending(pendingRes, &res); state == C.DuckDBError { + if ctx.Err() != nil { + return nil, ctx.Err() + } + dbErr := C.GoString(C.duckdb_result_error(&res)) C.duckdb_destroy_result(&res) return nil, errors.New(dbErr)