Skip to content

Commit beeda4c

Browse files
committed
Merge pull request #160 from capoferro/patch-1
Catch missing arguments for Query()
2 parents d10e2c8 + 3dc340b commit beeda4c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sqlite3.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"database/sql"
6161
"database/sql/driver"
6262
"errors"
63+
"fmt"
6364
"io"
6465
"runtime"
6566
"strings"
@@ -174,7 +175,7 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
174175
if s.(*SQLiteStmt).s != nil {
175176
na := s.NumInput()
176177
if len(args) < na {
177-
return nil, errors.New("args is not enough to execute query")
178+
return nil, fmt.Errorf("Not enough args to execute query. Expected %d, got %d.", na, len(args))
178179
}
179180
res, err = s.Exec(args[:na])
180181
if err != nil && err != driver.ErrSkip {
@@ -201,6 +202,9 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
201202
}
202203
s.(*SQLiteStmt).cls = true
203204
na := s.NumInput()
205+
if len(args) < na {
206+
return nil, fmt.Errorf("Not enough args to execute query. Expected %d, got %d.", na, len(args))
207+
}
204208
rows, err := s.Query(args[:na])
205209
if err != nil && err != driver.ErrSkip {
206210
s.Close()

0 commit comments

Comments
 (0)