]> Cypherpunks repositories - gostls13.git/commitdiff
exp/sql: NumInput() allow -1 to ignore checking.
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Wed, 16 Nov 2011 00:29:43 +0000 (16:29 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 16 Nov 2011 00:29:43 +0000 (16:29 -0800)
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

src/pkg/exp/sql/driver/driver.go
src/pkg/exp/sql/sql.go

index 9fc47905ce7aae79d8ca83047989e5b9593508c5..91a388421d17b40724b5660b214bb3b1866a4b6c 100644 (file)
@@ -97,6 +97,9 @@ type Stmt interface {
        Close() error
 
        // 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
 
        // Exec executes a query that doesn't return rows, such
index d3677afb3bae144ba4d20ea86eb91fae7885a993..c055fdd68c63648194d7165790e23f33efaf8449 100644 (file)
@@ -474,7 +474,10 @@ func (s *Stmt) Exec(args ...interface{}) (Result, error) {
        }
        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))
        }
 
@@ -570,7 +573,11 @@ func (s *Stmt) Query(args ...interface{}) (*Rows, error) {
        if err != nil {
                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))
        }
        sargs, err := subsetTypeArgs(args)