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) {
|
func TestBoolean(t *testing.T) {
|
||||||
db, err := sql.Open("sqlite3", ":memory:")
|
db, err := sql.Open("sqlite3", "./foo.db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to open database:", err)
|
t.Errorf("Failed to open database:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
defer os.Remove("./foo.db")
|
||||||
|
|
||||||
_, err = db.Exec("CREATE TABLE foo(id INTEGER, fbool BOOLEAN)")
|
_, err = db.Exec("CREATE TABLE foo(id INTEGER, fbool BOOLEAN)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -376,13 +377,12 @@ func TestBoolean(t *testing.T) {
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Unable to query foo table:", err)
|
t.Errorf("Unable to query foo table:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
counter := 0
|
||||||
seen := 0
|
|
||||||
|
|
||||||
var id int
|
var id int
|
||||||
var fbool bool
|
var fbool bool
|
||||||
|
@ -390,22 +390,48 @@ func TestBoolean(t *testing.T) {
|
||||||
for rows.Next(){
|
for rows.Next(){
|
||||||
if err := rows.Scan(&id, &fbool); err != nil {
|
if err := rows.Scan(&id, &fbool); err != nil {
|
||||||
t.Errorf("Unable to scan results:", err)
|
t.Errorf("Unable to scan results:", err)
|
||||||
continue
|
return
|
||||||
|
}
|
||||||
|
counter ++
|
||||||
}
|
}
|
||||||
|
|
||||||
if id == 1 && fbool != bool1 {
|
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)
|
t.Errorf("Value for id 1 should be %v, not %v", bool1, fbool)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if id == 2 && fbool != bool2 {
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
|
||||||
|
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 != 2 && fbool != false {
|
||||||
t.Errorf("Value for id 2 should be %v, not %v", bool2, fbool)
|
t.Errorf("Value for id 2 should be %v, not %v", bool2, fbool)
|
||||||
}
|
return
|
||||||
seen ++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if seen != 2 {
|
|
||||||
t.Errorf("Expected to see two bool")
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure "nonsense" triggered an error
|
// make sure "nonsense" triggered an error
|
||||||
rows, err = db.Query("SELECT id, fbool FROM foo where id=?;", 3)
|
rows, err = db.Query("SELECT id, fbool FROM foo where id=?;", 3)
|
||||||
|
|
Loading…
Reference in New Issue