mirror of
https://github.com/golang/go
synced 2024-11-20 03:04:40 -07:00
exp/sql: NumInput() allow -1 to ignore checking.
Some database driver can't get number of parameters. For example: http://support.microsoft.com/kb/240205/en-us So, added way to ignore checking number of parameters with return -1. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5376091
This commit is contained in:
parent
5b7827ec07
commit
5e5c5c2789
@ -97,6 +97,9 @@ type Stmt interface {
|
|||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
// NumInput returns the number of placeholder parameters.
|
// NumInput returns the number of placeholder parameters.
|
||||||
|
// -1 means the driver doesn't know how to count the number of
|
||||||
|
// placeholders, so we won't sanity check input here and instead let the
|
||||||
|
// driver deal with errors.
|
||||||
NumInput() int
|
NumInput() int
|
||||||
|
|
||||||
// Exec executes a query that doesn't return rows, such
|
// Exec executes a query that doesn't return rows, such
|
||||||
|
@ -474,7 +474,10 @@ func (s *Stmt) Exec(args ...interface{}) (Result, error) {
|
|||||||
}
|
}
|
||||||
defer releaseConn()
|
defer releaseConn()
|
||||||
|
|
||||||
if want := si.NumInput(); len(args) != want {
|
// -1 means the driver doesn't know how to count the number of
|
||||||
|
// placeholders, so we won't sanity check input here and instead let the
|
||||||
|
// driver deal with errors.
|
||||||
|
if want := si.NumInput(); want != -1 && len(args) != want {
|
||||||
return nil, fmt.Errorf("db: expected %d arguments, got %d", want, len(args))
|
return nil, fmt.Errorf("db: expected %d arguments, got %d", want, len(args))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,7 +573,11 @@ func (s *Stmt) Query(args ...interface{}) (*Rows, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(args) != si.NumInput() {
|
|
||||||
|
// -1 means the driver doesn't know how to count the number of
|
||||||
|
// placeholders, so we won't sanity check input here and instead let the
|
||||||
|
// driver deal with errors.
|
||||||
|
if want := si.NumInput(); want != -1 && len(args) != want {
|
||||||
return nil, fmt.Errorf("db: statement expects %d inputs; got %d", si.NumInput(), len(args))
|
return nil, fmt.Errorf("db: statement expects %d inputs; got %d", si.NumInput(), len(args))
|
||||||
}
|
}
|
||||||
sargs, err := subsetTypeArgs(args)
|
sargs, err := subsetTypeArgs(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user