Skip to content

Commit 2d16813

Browse files
committed
Cache bind count.
1 parent eb8e716 commit 2d16813

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

driver/driver.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e
301301
s.Close()
302302
return nil, util.TailErr
303303
}
304-
return &stmt{Stmt: s, tmRead: c.tmRead, tmWrite: c.tmWrite}, nil
304+
return &stmt{Stmt: s, tmRead: c.tmRead, tmWrite: c.tmWrite, inputs: -2}, nil
305305
}
306306

307307
func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
@@ -335,6 +335,7 @@ type stmt struct {
335335
*sqlite3.Stmt
336336
tmWrite sqlite3.TimeFormat
337337
tmRead sqlite3.TimeFormat
338+
inputs int
338339
}
339340

340341
var (
@@ -345,12 +346,17 @@ var (
345346
)
346347

347348
func (s *stmt) NumInput() int {
349+
if s.inputs >= -1 {
350+
return s.inputs
351+
}
348352
n := s.Stmt.BindCount()
349353
for i := 1; i <= n; i++ {
350354
if s.Stmt.BindName(i) != "" {
355+
s.inputs = -1
351356
return -1
352357
}
353358
}
359+
s.inputs = n
354360
return n
355361
}
356362

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

392-
func (s *stmt) setupBindings(args []driver.NamedValue) error {
393-
err := s.Stmt.ClearBindings()
394-
if err != nil {
395-
return err
396-
}
397-
398+
func (s *stmt) setupBindings(args []driver.NamedValue) (err error) {
398399
var ids [3]int
399400
for _, arg := range args {
400401
ids := ids[:0]

0 commit comments

Comments
 (0)