forked from mirror/go-sqlcipher
fix TestBoolean
This commit is contained in:
parent
1bfaa5b7d2
commit
ed17eae07a
|
@ -342,12 +342,13 @@ func TestTimestamp(t *testing.T) {
|
|||
|
||||
|
||||
func TestBoolean(t *testing.T) {
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
db, err := sql.Open("sqlite3", "./foo.db")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to open database:", err)
|
||||
return
|
||||
}
|
||||
defer db.Close()
|
||||
defer os.Remove("./foo.db")
|
||||
|
||||
_, err = db.Exec("CREATE TABLE foo(id INTEGER, fbool BOOLEAN)")
|
||||
if err != nil {
|
||||
|
@ -376,36 +377,61 @@ func TestBoolean(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
rows, err := db.Query("SELECT id, fbool FROM foo where (fbool is ?) or (fbool is ?);", true, false)
|
||||
rows, err := db.Query("SELECT id, fbool FROM foo where fbool is ?", bool1)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to query foo table:", err)
|
||||
return
|
||||
}
|
||||
counter := 0
|
||||
|
||||
var id int
|
||||
var fbool bool
|
||||
|
||||
for rows.Next(){
|
||||
if err := rows.Scan(&id, &fbool); err != nil {
|
||||
t.Errorf("Unable to scan results:", err)
|
||||
return
|
||||
}
|
||||
counter ++
|
||||
}
|
||||
|
||||
if counter != 1{
|
||||
t.Errorf("Expected 1 row but %v", counter)
|
||||
return
|
||||
}
|
||||
|
||||
if id!=1 && fbool != true {
|
||||
t.Errorf("Value for id 1 should be %v, not %v", bool1, fbool)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
rows, err = db.Query("SELECT id, fbool FROM foo where fbool is ?", bool2)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to query foo table:", err)
|
||||
return
|
||||
}
|
||||
|
||||
seen := 0
|
||||
counter = 0
|
||||
|
||||
var id int
|
||||
var fbool bool
|
||||
|
||||
for rows.Next() {
|
||||
for rows.Next(){
|
||||
if err := rows.Scan(&id, &fbool); err != nil {
|
||||
t.Errorf("Unable to scan results:", err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
counter ++
|
||||
}
|
||||
|
||||
if id == 1 && fbool != bool1 {
|
||||
t.Errorf("Value for id 1 should be %v, not %v", bool1, fbool)
|
||||
if counter != 1{
|
||||
t.Errorf("Expected 1 row but %v", counter)
|
||||
return
|
||||
}
|
||||
|
||||
if id == 2 && fbool != bool2 {
|
||||
if id != 2 && fbool != false {
|
||||
t.Errorf("Value for id 2 should be %v, not %v", bool2, fbool)
|
||||
}
|
||||
seen ++
|
||||
return
|
||||
}
|
||||
|
||||
if seen != 2 {
|
||||
t.Errorf("Expected to see two bool")
|
||||
}
|
||||
|
||||
// make sure "nonsense" triggered an error
|
||||
rows, err = db.Query("SELECT id, fbool FROM foo where id=?;", 3)
|
||||
|
|
Loading…
Reference in New Issue