aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjander <jander.sy@163.com>2012-05-27 00:09:12 +0800
committerjander <jander.sy@163.com>2012-05-27 00:09:12 +0800
commited17eae07aa835fffe64c6fbab3fc42ce2caa644 (patch)
tree7cc60a80c8e653796bc25920da056fb21a5ab5e3
parentadd bool type test: TestBoolean (diff)
downloadgolite-ed17eae07aa835fffe64c6fbab3fc42ce2caa644.tar.gz
golite-ed17eae07aa835fffe64c6fbab3fc42ce2caa644.tar.xz
fix TestBoolean
-rw-r--r--sqlite3_test.go62
1 files changed, 44 insertions, 18 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go
index 8d4be1f..f4b80bc 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -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
}
-
- 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
- }
-
- if id == 1 && fbool != bool1 {
- t.Errorf("Value for id 1 should be %v, not %v", bool1, fbool)
+ 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
+ }
+
+ counter = 0
- if id == 2 && fbool != bool2 {
- t.Errorf("Value for id 2 should be %v, not %v", bool2, fbool)
+ for rows.Next(){
+ if err := rows.Scan(&id, &fbool); err != nil {
+ t.Errorf("Unable to scan results:", err)
+ return
}
- seen ++
+ counter ++
}
-
- if seen != 2 {
- t.Errorf("Expected to see two bool")
+
+ 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)
+ return
+ }
+
// make sure "nonsense" triggered an error
rows, err = db.Query("SELECT id, fbool FROM foo where id=?;", 3)
@@ -419,4 +445,4 @@ func TestBoolean(t *testing.T) {
if err == nil {
t.Errorf("Expected error from \"nonsense\" bool")
}
-}
+} \ No newline at end of file