Skip to content

Commit

Permalink
Handle some errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jan 17, 2025
1 parent 9132f74 commit 407e13d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
10 changes: 6 additions & 4 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive
old := s.Stmt.Conn().SetInterrupt(ctx)
defer s.Stmt.Conn().SetInterrupt(old)

err = s.Stmt.Exec()
s.Stmt.ClearBindings()
err = errors.Join(
s.Stmt.Exec(),
s.Stmt.ClearBindings())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -604,8 +605,9 @@ var (
)

func (r *rows) Close() error {
r.Stmt.ClearBindings()
return r.Stmt.Reset()
return errors.Join(
r.Stmt.Reset(),
r.Stmt.ClearBindings())
}

func (r *rows) Columns() []string {
Expand Down
8 changes: 6 additions & 2 deletions ext/closure/closure.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
if curr.depth >= maxDepth {
continue
}
stmt.BindInt64(1, curr.id)
if err := stmt.BindInt64(1, curr.id); err != nil {
return err
}
for stmt.Step() {
if stmt.ColumnType(0) == sqlite3.INTEGER {
next := stmt.ColumnInt64(0)
Expand All @@ -225,7 +227,9 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
}
}
}
stmt.Reset()
if err := stmt.Reset(); err != nil {
return err
}
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion ext/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
return err
}
if c.table.header {
c.Next() // skip header
err = c.Next() // skip header
if err != nil {
return err
}
}
c.rowID = 0
return c.Next()
Expand Down
5 changes: 3 additions & 2 deletions ext/pivot/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ func declare(db *sqlite3.Conn, _, _, _ string, arg ...string) (res *table, err e
}

func (t *table) Close() error {
var errs []error
for _, c := range t.cols {
c.Close()
errs = append(errs, c.Close())
}
return nil
return errors.Join(errs...)
}

func (t *table) BestIndex(idx *sqlite3.IndexInfo) error {
Expand Down
12 changes: 8 additions & 4 deletions ext/statement/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package statement

import (
"encoding/json"
"errors"
"strconv"
"strings"
"unsafe"
Expand Down Expand Up @@ -150,17 +151,20 @@ type cursor struct {
func (c *cursor) Close() error {
if c.stmt == c.table.stmt {
c.table.inuse = false
c.stmt.ClearBindings()
return c.stmt.Reset()
return errors.Join(
c.stmt.Reset(),
c.stmt.ClearBindings())
}
return c.stmt.Close()
}

func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
c.arg = arg
c.rowID = 0
c.stmt.ClearBindings()
if err := c.stmt.Reset(); err != nil {
err := errors.Join(
c.stmt.Reset(),
c.stmt.ClearBindings())
if err != nil {
return err
}

Expand Down
5 changes: 4 additions & 1 deletion func.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func finalCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp uint32)
db := ctx.Value(connKey{}).(*Conn)
fn, handle := callbackAggregate(db, pAgg, pApp)
fn.Value(Context{db, pCtx})
util.DelHandle(ctx, handle)
if err := util.DelHandle(ctx, handle); err != nil {
Context{db, pCtx}.ResultError(err)
return // notest
}
}

func valueCallback(ctx context.Context, mod api.Module, pCtx, pAgg uint32) {
Expand Down
7 changes: 3 additions & 4 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,14 @@ func (s *Stmt) BindTime(param int, value time.Time, format TimeFormat) error {
}
switch v := format.Encode(value).(type) {
case string:
s.BindText(param, v)
return s.BindText(param, v)
case int64:
s.BindInt64(param, v)
return s.BindInt64(param, v)
case float64:
s.BindFloat(param, v)
return s.BindFloat(param, v)
default:
panic(util.AssertErr())
}
return nil
}

func (s *Stmt) bindRFC3339Nano(param int, value time.Time) error {
Expand Down

0 comments on commit 407e13d

Please sign in to comment.