Fixes Queryer

This commit is contained in:
mattn 2013-09-09 13:44:24 +09:00
parent 77ebf39cf9
commit f595dd9955
1 changed files with 8 additions and 5 deletions

View File

@ -136,14 +136,13 @@ func (c *SQLiteConn) AutoCommit() bool {
// Implements Execer // Implements Execer
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) { func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
var res driver.Result
for { for {
s, err := c.Prepare(query) s, err := c.Prepare(query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
na := s.NumInput() na := s.NumInput()
res, err = s.Exec(args[:na]) res, err := s.Exec(args[:na])
if err != nil && err != driver.ErrSkip { if err != nil && err != driver.ErrSkip {
s.Close() s.Close()
return nil, err return nil, err
@ -160,14 +159,13 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
// Implements Queryer // Implements Queryer
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) { func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
var rows driver.Rows
for { for {
s, err := c.Prepare(query) s, err := c.Prepare(query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
na := s.NumInput() na := s.NumInput()
rows, err = s.Query(args[:na]) rows, err := s.Query(args[:na])
if err != nil && err != driver.ErrSkip { if err != nil && err != driver.ErrSkip {
s.Close() s.Close()
return nil, err return nil, err
@ -177,6 +175,7 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
if tail == "" { if tail == "" {
return rows, nil return rows, nil
} }
s.Close()
query = tail query = tail
} }
} }
@ -444,8 +443,12 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
return io.EOF return io.EOF
} }
if rv != C.SQLITE_ROW { if rv != C.SQLITE_ROW {
rv = C.sqlite3_reset(rc.s.s)
if rv != C.SQLITE_OK {
return ErrNo(rv) return ErrNo(rv)
} }
return nil
}
if rc.decltype == nil { if rc.decltype == nil {
rc.decltype = make([]string, rc.nc) rc.decltype = make([]string, rc.nc)