aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_test.go
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2012-11-04 16:06:42 -0800
committermattn <mattn.jp@gmail.com>2012-11-04 16:06:42 -0800
commit68952ca0661526d253d3a9e7551d0612b357bd2b (patch)
tree46a47f5d8f6be8abf441663320ce7cec96a8730b /sqlite3_test.go
parentMerge pull request #26 from cookieo9/noexample (diff)
parentAdd support for extracting 2006-01-02 formatted timestamps. (diff)
downloadgolite-68952ca0661526d253d3a9e7551d0612b357bd2b.tar.gz
golite-68952ca0661526d253d3a9e7551d0612b357bd2b.tar.xz
Merge pull request #28 from lye/master
Add support for extracting 2006-01-02 formatted timestamps.
Diffstat (limited to 'sqlite3_test.go')
-rw-r--r--sqlite3_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go
index aaeb096..4ff8d6c 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -400,3 +400,63 @@ func TestBoolean(t *testing.T) {
t.Error("Expected error from \"nonsense\" bool")
}
}
+
+func TestDateOnlyTimestamp(t *testing.T) {
+ // make sure that timestamps without times are extractable. these are generated when
+ // e.g., you use the sqlite `DATE()` built-in.
+
+ db, er := sql.Open("sqlite3", "db.sqlite")
+ if er != nil {
+ t.Fatal(er)
+ }
+ defer func() {
+ db.Close()
+ os.Remove("db.sqlite")
+ }()
+
+ _, er = db.Exec(`
+ CREATE TABLE test
+ ( entry_id INTEGER PRIMARY KEY AUTOINCREMENT
+ , entry_published TIMESTAMP NOT NULL
+ )
+ `)
+ if er != nil {
+ t.Fatal(er)
+ }
+
+ _, er = db.Exec(`
+ INSERT INTO test VALUES ( 1, '2012-11-04')
+ `)
+ if er != nil {
+ t.Fatal(er)
+ }
+
+ rows, er := db.Query("SELECT entry_id, entry_published FROM test")
+ if er != nil {
+ t.Fatal(er)
+ }
+ defer rows.Close()
+
+ if !rows.Next() {
+ if er := rows.Err() ; er != nil {
+ t.Fatal(er)
+ } else {
+ t.Fatalf("Unable to extract row containing date-only timestamp")
+ }
+ }
+
+ var entryId int64
+ var entryPublished time.Time
+
+ if er := rows.Scan(&entryId, &entryPublished) ; er != nil {
+ t.Fatal(er)
+ }
+
+ if entryId != 1 {
+ t.Errorf("EntryId does not match inserted value")
+ }
+
+ if entryPublished.Year() != 2012 || entryPublished.Month() != 11 || entryPublished.Day() != 4 {
+ t.Errorf("Extracted time does not match inserted value")
+ }
+}