database/sql expects io.EOF after all rows have been Next'ed

Return io.EOF, so rows.Next() will automatically call rows.Close()
after all results have been returned.
This commit is contained in:
Sven Engelhardt 2012-03-01 17:52:03 +01:00 committed by mattn
parent fdc20cdbcb
commit 81a88cec73
1 changed files with 5 additions and 1 deletions

View File

@ -19,9 +19,10 @@ _sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
*/ */
import "C" import "C"
import ( import (
"errors"
"database/sql" "database/sql"
"database/sql/driver" "database/sql/driver"
"errors"
"io"
"unsafe" "unsafe"
) )
@ -247,6 +248,9 @@ func (rc *SQLiteRows) Columns() []string {
func (rc *SQLiteRows) Next(dest []driver.Value) error { func (rc *SQLiteRows) Next(dest []driver.Value) error {
rv := C.sqlite3_step(rc.s.s) rv := C.sqlite3_step(rc.s.s)
if rv == C.SQLITE_DONE {
return io.EOF
}
if rv != C.SQLITE_ROW { if rv != C.SQLITE_ROW {
return errors.New(C.GoString(C.sqlite3_errmsg(rc.s.c.db))) return errors.New(C.GoString(C.sqlite3_errmsg(rc.s.c.db)))
} }