Browse files

re-sync mattn/go-sqlite from its 81a88cec7

  • Loading branch information...
1 parent 994a153 commit f881b94ee5a58ab32b504446fc99f5a485660bc8 @bradfitz committed Mar 10, 2012
Showing with 56 additions and 1 deletion.
  1. +5 −1 src/github.com/mattn/go-sqlite3/sqlite3.go
  2. +51 −0 src/github.com/mattn/go-sqlite3/sqlite3_test.go
View
6 src/github.com/mattn/go-sqlite3/sqlite3.go
@@ -19,9 +19,10 @@ _sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
*/
import "C"
import (
- "errors"
"database/sql"
"database/sql/driver"
+ "errors"
+ "io"
"unsafe"
)
@@ -247,6 +248,9 @@ func (rc *SQLiteRows) Columns() []string {
func (rc *SQLiteRows) Next(dest []driver.Value) error {
rv := C.sqlite3_step(rc.s.s)
+ if rv == C.SQLITE_DONE {
+ return io.EOF
+ }
if rv != C.SQLITE_ROW {
return errors.New(C.GoString(C.sqlite3_errmsg(rc.s.c.db)))
}
View
51 src/github.com/mattn/go-sqlite3/sqlite3_test.go
@@ -209,3 +209,54 @@ func TestDelete(t *testing.T) {
t.Errorf("Fetched row but expected not rows")
}
}
+
+func TestBooleanRoundtrip(t *testing.T) {
+ db, err := sql.Open("sqlite3", "./foo.db")
+ if err != nil {
+ t.Errorf("Tailed to open database:", err)
+ return
+ }
+ defer os.Remove("./foo.db")
+
+ _, err = db.Exec("DROP TABLE foo")
+ _, err = db.Exec("CREATE TABLE foo(id INTEGER, value BOOL)")
+ if err != nil {
+ t.Errorf("Failed to create table:", err)
+ return
+ }
+
+ _, err = db.Exec("INSERT INTO foo(id, value) VALUES(1, ?)", true)
+ if err != nil {
+ t.Errorf("Failed to insert true value:", err)
+ return
+ }
+
+ _, err = db.Exec("INSERT INTO foo(id, value) VALUES(2, ?)", false)
+ if err != nil {
+ t.Errorf("Failed to insert false value:", err)
+ return
+ }
+
+ rows, err := db.Query("SELECT id, value FROM foo")
+ if err != nil {
+ t.Errorf("Unable to query foo table:", err)
+ return
+ }
+
+ for rows.Next() {
+ var id int
+ var value bool
+
+ if err := rows.Scan(&id, &value); err != nil {
+ t.Errorf("Unable to scan results:", err)
+ continue
+ }
+
+ if id == 1 && !value {
+ t.Errorf("Value for id 1 should be true, not false")
+
+ } else if id == 2 && value {
+ t.Errorf("Value for id 2 should be false, not true")
+ }
+ }
+}

0 comments on commit f881b94

Please sign in to comment.