From 53e8d03ecf939c5b3a66e4afc37d434d7d7e5f36 Mon Sep 17 00:00:00 2001 From: lye Date: Tue, 7 Feb 2012 06:56:36 +0800 Subject: [PATCH] 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. --- sqlite3_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sqlite3_test.go b/sqlite3_test.go index 035ffa8..a76d86f 100644 --- a/sqlite3_test.go +++ b/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") + } + } +}