mirror of https://github.com/mattn/go-sqlite3.git
Z suffix should be no-op
This commit is contained in:
parent
5f64400729
commit
dee1a37fe1
|
@ -650,6 +650,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
|
|||
switch rc.decltype[i] {
|
||||
case "timestamp", "datetime", "date":
|
||||
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
|
||||
|
|
|
@ -8,7 +8,9 @@ package sqlite3
|
|||
import (
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -1018,3 +1020,41 @@ func TestStringContainingZero(t *testing.T) {
|
|||
t.Error("Failed to db.QueryRow: not matched results")
|
||||
}
|
||||
}
|
||||
|
||||
const CurrentTimeStamp = "2006-01-02 15:04:05"
|
||||
|
||||
type TimeStamp struct{ *time.Time }
|
||||
|
||||
func (t TimeStamp) Scan(value interface{}) error {
|
||||
fmt.Printf("%T\n", value)
|
||||
|
||||
var err error
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
*t.Time, err = time.Parse(CurrentTimeStamp, v)
|
||||
case []byte:
|
||||
*t.Time, err = time.Parse(CurrentTimeStamp, string(v))
|
||||
default:
|
||||
err = errors.New("invalid type for current_timestamp")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (t TimeStamp) Value() (driver.Value, error) {
|
||||
return t.Time.Format(CurrentTimeStamp), nil
|
||||
}
|
||||
|
||||
func TestDateTimeNow(t *testing.T) {
|
||||
tempFilename := TempFilename()
|
||||
db, err := sql.Open("sqlite3", tempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
var d time.Time
|
||||
err = db.QueryRow("SELECT datetime('now')").Scan(TimeStamp{&d})
|
||||
if err != nil {
|
||||
t.Fatal("Failed to scan datetime:", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue