From ff38c8ec02230a8eb61cb8b93cad1dc2f5411e74 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 22 Mar 2015 04:29:14 +0900 Subject: [PATCH] Revert a6c208564eccf3c6743f608ef88398a4ca84c5eb --- sqlite3.go | 44 +++----------------------------------------- sqlite3_test.go | 36 ------------------------------------ 2 files changed, 3 insertions(+), 77 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index ca0180b..d384202 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -382,18 +382,6 @@ func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) { t = strings.TrimSpace(C.GoString(tail)) } nv := int(C.sqlite3_bind_parameter_count(s)) - /* - if nv > 0 { - pn := C.GoString(C.sqlite3_bind_parameter_name(s, 1)) - // TODO: map argument for named parameters - if len(pn) > 0 && pn[0] == '$' && pn[1] != '1' { - nv = -1 - } - if len(pn) > 0 && pn[0] != '?' { - nv = -1 - } - } - */ ss := &SQLiteStmt{c: c, s: s, nv: nv, t: t} runtime.SetFinalizer(ss, (*SQLiteStmt).Close) return ss, nil @@ -434,35 +422,9 @@ func (s *SQLiteStmt) bind(args []driver.Value) error { var vargs []bindArg narg := len(args) - if s.nv == -1 { - /* TODO: map argument for named parameters - if narg == 1 { - if m, ok := args[0].(map[string]driver.Value); ok { - for k, v := range m { - pn := C.CString(k) - if pi := int(C.sqlite3_bind_parameter_index(s.s, pn)); pi > 0 { - vargs = append(vargs, bindArg{pi, v}) - } - C.free(unsafe.Pointer(pn)) - } - } - narg = 0 - } - */ - if narg > 0 { - for i := 0; i < narg; i++ { - pn := C.CString(fmt.Sprint(i + 1)) - if pi := int(C.sqlite3_bind_parameter_index(s.s, pn)); pi > 0 { - vargs = append(vargs, bindArg{pi, args[i]}) - } - C.free(unsafe.Pointer(pn)) - } - } - } else { - vargs = make([]bindArg, narg) - for i, v := range args { - vargs[i] = bindArg{i + 1, v} - } + vargs = make([]bindArg, narg) + for i, v := range args { + vargs[i] = bindArg{i + 1, v} } for _, varg := range vargs { diff --git a/sqlite3_test.go b/sqlite3_test.go index 1d06fd4..81113fc 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -909,39 +909,3 @@ func TestVersion(t *testing.T) { t.Errorf("Version failed %q, %d, %q\n", s, n, id) } } - -func TestNumberNamedParams(t *testing.T) { - tempFilename := TempFilename() - db, err := sql.Open("sqlite3", tempFilename) - if err != nil { - t.Fatal("Failed to open database:", err) - } - defer os.Remove(tempFilename) - defer db.Close() - - _, err = db.Exec(` - create table foo (id integer, name text, extra text); - `) - if err != nil { - t.Error("Failed to call db.Query:", err) - } - - _, err = db.Exec(`insert into foo(id, name, extra) values($1, $2, $2)`, 1, "foo") - if err != nil { - t.Error("Failed to call db.Exec:", err) - } - - row := db.QueryRow(`select id, name, extra where id = $1 and extra = $2`, 1, "foo") - if row == nil { - t.Error("Failed to call db.QueryRow") - } - var id int - var extra string - err = row.Scan(&id, &extra) - if err != nil { - t.Error("Failed to db.Scan:", err) - } - if id != 1 || extra != "foo" { - t.Error("Failed to db.QueryRow: not matched results") - } -}