From 1ca536cf83c71f5960c79697d5aee49d09f0bcd5 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 12 Sep 2013 10:46:35 +0900 Subject: [PATCH] Disable Execer/Queryer until database/sql/driver implement QueryRow: #82 --- sqlite3.go | 120 +++++++++++++++++++++++---------------------- sqlite3_test.go | 128 ++++++++++++++++++++++++------------------------ 2 files changed, 126 insertions(+), 122 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index c3abc78..9993b18 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -134,65 +134,67 @@ func (c *SQLiteConn) AutoCommit() bool { return int(C.sqlite3_get_autocommit(c.db)) != 0 } -// Implements Execer -func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) { - tx, err := c.Begin() - if err != nil { - return nil, err - } - for { - s, err := c.Prepare(query) - if err != nil { - tx.Rollback() - return nil, err - } - na := s.NumInput() - res, err := s.Exec(args[:na]) - if err != nil && err != driver.ErrSkip { - tx.Rollback() - s.Close() - return nil, err - } - args = args[na:] - tail := s.(*SQLiteStmt).t - if tail == "" { - tx.Commit() - return res, nil - } - s.Close() - query = tail - } -} - -// Implements Queryer -func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) { - tx, err := c.Begin() - if err != nil { - return nil, err - } - for { - s, err := c.Prepare(query) - if err != nil { - tx.Rollback() - return nil, err - } - na := s.NumInput() - rows, err := s.Query(args[:na]) - if err != nil && err != driver.ErrSkip { - tx.Rollback() - s.Close() - return nil, err - } - args = args[na:] - tail := s.(*SQLiteStmt).t - if tail == "" { - tx.Commit() - return rows, nil - } - s.Close() - query = tail - } -} +// TODO: Execer & Queryer currently disabled +// https://github.com/mattn/go-sqlite3/issues/82 +//// Implements Execer +//func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) { +// tx, err := c.Begin() +// if err != nil { +// return nil, err +// } +// for { +// s, err := c.Prepare(query) +// if err != nil { +// tx.Rollback() +// return nil, err +// } +// na := s.NumInput() +// res, err := s.Exec(args[:na]) +// if err != nil && err != driver.ErrSkip { +// tx.Rollback() +// s.Close() +// return nil, err +// } +// args = args[na:] +// tail := s.(*SQLiteStmt).t +// if tail == "" { +// tx.Commit() +// return res, nil +// } +// s.Close() +// query = tail +// } +//} +// +//// Implements Queryer +//func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) { +// tx, err := c.Begin() +// if err != nil { +// return nil, err +// } +// for { +// s, err := c.Prepare(query) +// if err != nil { +// tx.Rollback() +// return nil, err +// } +// na := s.NumInput() +// rows, err := s.Query(args[:na]) +// if err != nil && err != driver.ErrSkip { +// tx.Rollback() +// s.Close() +// return nil, err +// } +// args = args[na:] +// tail := s.(*SQLiteStmt).t +// if tail == "" { +// tx.Commit() +// return rows, nil +// } +// s.Close() +// query = tail +// } +//} func (c *SQLiteConn) exec(cmd string) error { pcmd := C.CString(cmd) diff --git a/sqlite3_test.go b/sqlite3_test.go index 5b4a05f..ec86aef 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -580,67 +580,69 @@ func TestTransaction(t *testing.T) { } } -func TestExecer(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); - insert into foo(id) values(?); - insert into foo(id) values(?); - insert into foo(id) values(?); - `, 1, 2, 3) - if err != nil { - t.Error("Failed to call db.Exec:", err) - } - if err != nil { - t.Error("Failed to call res.RowsAffected:", err) - } -} - -func TestQueryer(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); - `) - if err != nil { - t.Error("Failed to call db.Query:", err) - } - - rows, err := db.Query(` - insert into foo(id) values(?); - insert into foo(id) values(?); - insert into foo(id) values(?); - select id from foo order by id; - `, 3, 2, 1) - if err != nil { - t.Error("Failed to call db.Query:", err) - } - defer rows.Close() - n := 1 - if rows != nil { - for rows.Next() { - var id int - err = rows.Scan(&id) - if err != nil { - t.Error("Failed to db.Query:", err) - } - if id != n { - t.Error("Failed to db.Query: not matched results") - } - } - } -} +// TODO: Execer & Queryer currently disabled +// https://github.com/mattn/go-sqlite3/issues/82 +//func TestExecer(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); +// insert into foo(id) values(?); +// insert into foo(id) values(?); +// insert into foo(id) values(?); +// `, 1, 2, 3) +// if err != nil { +// t.Error("Failed to call db.Exec:", err) +// } +// if err != nil { +// t.Error("Failed to call res.RowsAffected:", err) +// } +//} +// +//func TestQueryer(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); +// `) +// if err != nil { +// t.Error("Failed to call db.Query:", err) +// } +// +// rows, err := db.Query(` +// insert into foo(id) values(?); +// insert into foo(id) values(?); +// insert into foo(id) values(?); +// select id from foo order by id; +// `, 3, 2, 1) +// if err != nil { +// t.Error("Failed to call db.Query:", err) +// } +// defer rows.Close() +// n := 1 +// if rows != nil { +// for rows.Next() { +// var id int +// err = rows.Scan(&id) +// if err != nil { +// t.Error("Failed to db.Query:", err) +// } +// if id != n { +// t.Error("Failed to db.Query: not matched results") +// } +// } +// } +//}