aboutsummaryrefslogtreecommitdiff
path: root/sqlite3.go
diff options
context:
space:
mode:
authorlye <lye@>2012-11-03 19:45:58 -0500
committerlye <lye@>2012-11-03 19:45:58 -0500
commitdcd44f511811bacb58241dd4de752177e7286967 (patch)
tree46a47f5d8f6be8abf441663320ce7cec96a8730b /sqlite3.go
parentMerge pull request #26 from cookieo9/noexample (diff)
downloadgolite-dcd44f511811bacb58241dd4de752177e7286967.tar.gz
golite-dcd44f511811bacb58241dd4de752177e7286967.tar.xz
Add support for extracting 2006-01-02 formatted timestamps.
SQLite3 stores timestamps very naively -- they're completely untyped, and can contain any value. The previous implementation always inserts values in the 'datetime' format, and returns an error when attempting to extract a field with a different format. Some legacy databases, unfortunately, were generated using the 'date' SQLite3 function, which produces rows in the '2006-01-02' format. This patch adds a special case so that these rows can be extracted without error.
Diffstat (limited to 'sqlite3.go')
-rw-r--r--sqlite3.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 270403d..90a1241 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -27,6 +27,7 @@ import (
)
const SQLiteTimestampFormat = "2006-01-02 15:04:05"
+const SQLiteDateFormat = "2006-01-02"
func init() {
sql.Register("sqlite3", &SQLiteDriver{})
@@ -313,7 +314,10 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
if rc.decltype[i] == "timestamp" {
dest[i], err = time.Parse(SQLiteTimestampFormat, s)
if err != nil {
- return err
+ dest[i], err = time.Parse(SQLiteDateFormat, s)
+ if err != nil {
+ return err
+ }
}
} else {
dest[i] = s