Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a case in Next scan to fix issue #190 and issue #316 #468

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,27 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
t = t.In(rc.s.c.loc)
}
dest[i] = t
// this case is for a nullable datetime typed colomn a chance to be parsed
// to resolve the problem in issue #190 and issue #316
case "":
var t time.Time
s = strings.TrimSuffix(s, "Z")
for _, format := range SQLiteTimestampFormats {
if timeVal, err = time.ParseInLocation(format, s, time.UTC); err == nil {
t = timeVal
break
}
}
// if not parsed as a datetime type successfully, do as the default case does
if err != nil {
dest[i] = []byte(s)
} else {
if rc.s.c.loc != nil {
t = t.In(rc.s.c.loc)
}
dest[i] = t
}

default:
dest[i] = []byte(s)
}
Expand Down
2 changes: 1 addition & 1 deletion sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ func TestDateTimeNow(t *testing.T) {
defer db.Close()

var d time.Time
err = db.QueryRow("SELECT datetime('now')").Scan(TimeStamp{&d})
err = db.QueryRow("SELECT datetime('now')").Scan(&d)
if err != nil {
t.Fatal("Failed to scan datetime:", err)
}
Expand Down