forked from mirror/go-sqlite3
Added additional testcase for boolean roundtrips
This test creates a simple table, inserts some dummy boolean values, then pulls them back out to ensure they are marshalled correctly.
This commit is contained in:
parent
7c18f62cf1
commit
275bdb282a
|
@ -209,3 +209,54 @@ func TestDelete(t *testing.T) {
|
||||||
t.Errorf("Fetched row but expected not rows")
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue