Skip to content

Commit

Permalink
Prepare: Break on context cancelation
Browse files Browse the repository at this point in the history
  • Loading branch information
tgulacsi committed Sep 21, 2020
1 parent 132f830 commit 1013913
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,26 @@ func (c *conn) prepareContextNotLocked(ctx context.Context, query string) (drive
defer func() {
C.free(unsafe.Pointer(cSQL))
}()
done := make(chan struct{})
go func() {
select {
case <-done:
return
case <-ctx.Done():
select {
case <-done:
return
default:
_ = c.Break()
}
}
}()
st := statement{conn: c, query: query}
if C.dpiConn_prepareStmt(c.dpiConn, 0, cSQL, C.uint32_t(len(query)), nil, 0,
failed := C.dpiConn_prepareStmt(c.dpiConn, 0, cSQL, C.uint32_t(len(query)), nil, 0,
(**C.dpiStmt)(unsafe.Pointer(&st.dpiStmt)),
) == C.DPI_FAILURE {
) == C.DPI_FAILURE
close(done)
if failed {
return nil, maybeBadConn(fmt.Errorf("Prepare: %s: %w", query, c.getError()), c)
}
if C.dpiStmt_getInfo(st.dpiStmt, &st.dpiStmtInfo) == C.DPI_FAILURE {
Expand Down

0 comments on commit 1013913

Please sign in to comment.