Skip to content

Commit

Permalink
Cache bind count.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jun 19, 2024
1 parent eb8e716 commit 2d16813
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e
s.Close()
return nil, util.TailErr
}
return &stmt{Stmt: s, tmRead: c.tmRead, tmWrite: c.tmWrite}, nil
return &stmt{Stmt: s, tmRead: c.tmRead, tmWrite: c.tmWrite, inputs: -2}, nil
}

func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
Expand Down Expand Up @@ -335,6 +335,7 @@ type stmt struct {
*sqlite3.Stmt
tmWrite sqlite3.TimeFormat
tmRead sqlite3.TimeFormat
inputs int
}

var (
Expand All @@ -345,12 +346,17 @@ var (
)

func (s *stmt) NumInput() int {
if s.inputs >= -1 {
return s.inputs
}
n := s.Stmt.BindCount()
for i := 1; i <= n; i++ {
if s.Stmt.BindName(i) != "" {
s.inputs = -1
return -1
}
}
s.inputs = n
return n
}

Expand Down Expand Up @@ -389,12 +395,7 @@ func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driv
return &rows{ctx: ctx, stmt: s}, nil
}

func (s *stmt) setupBindings(args []driver.NamedValue) error {
err := s.Stmt.ClearBindings()
if err != nil {
return err
}

func (s *stmt) setupBindings(args []driver.NamedValue) (err error) {
var ids [3]int
for _, arg := range args {
ids := ids[:0]
Expand Down

0 comments on commit 2d16813

Please sign in to comment.