Fix error on Execer. Close #124

This commit is contained in:
mattn 2014-06-26 03:54:09 +09:00
parent d56eb93ecb
commit d9e7576acf
2 changed files with 66 additions and 65 deletions

View File

@ -153,13 +153,16 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
if err != nil {
return nil, err
}
var res driver.Result
if s.(*SQLiteStmt).s != nil {
na := s.NumInput()
res, err := s.Exec(args[:na])
res, err = s.Exec(args[:na])
if err != nil && err != driver.ErrSkip {
s.Close()
return nil, err
}
args = args[na:]
}
tail := s.(*SQLiteStmt).t
if tail == "" {
return res, nil

View File

@ -1,7 +1,6 @@
package sqlite3
import (
"./sqltest"
"crypto/rand"
"database/sql"
"encoding/hex"
@ -9,6 +8,8 @@ import (
"path/filepath"
"testing"
"time"
"./sqltest"
)
func TempFilename() string {
@ -639,29 +640,26 @@ func TestSuite(t *testing.T) {
// 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 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); -- one comment
insert into foo(id) values(?);
insert into foo(id) values(?);
insert into foo(id) values(?); -- another comment
`, 1, 2, 3)
if err != nil {
t.Error("Failed to call db.Exec:", err)
}
}
//func TestQueryer(t *testing.T) {
// tempFilename := TempFilename()
// db, err := sql.Open("sqlite3", tempFilename)