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] {
|
switch rc.decltype[i] {
|
||||||
case "timestamp", "datetime", "date":
|
case "timestamp", "datetime", "date":
|
||||||
var t time.Time
|
var t time.Time
|
||||||
|
s = strings.TrimSuffix(s, "Z")
|
||||||
for _, format := range SQLiteTimestampFormats {
|
for _, format := range SQLiteTimestampFormats {
|
||||||
if timeVal, err = time.ParseInLocation(format, s, time.UTC); err == nil {
|
if timeVal, err = time.ParseInLocation(format, s, time.UTC); err == nil {
|
||||||
t = timeVal
|
t = timeVal
|
||||||
|
|
|
@ -8,7 +8,9 @@ package sqlite3
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"database/sql/driver"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -65,7 +67,7 @@ func TestOpen(t *testing.T) {
|
||||||
for option, expectedPass := range cases {
|
for option, expectedPass := range cases {
|
||||||
result, err := doTestOpen(t, option)
|
result, err := doTestOpen(t, option)
|
||||||
if result == "" {
|
if result == "" {
|
||||||
if ! expectedPass {
|
if !expectedPass {
|
||||||
errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
|
errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
|
||||||
t.Fatal(errmsg)
|
t.Fatal(errmsg)
|
||||||
}
|
}
|
||||||
|
@ -1018,3 +1020,41 @@ func TestStringContainingZero(t *testing.T) {
|
||||||
t.Error("Failed to db.QueryRow: not matched results")
|
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