diff options
author | mattn <mattn.jp@gmail.com> | 2015-03-05 01:17:38 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2015-03-05 01:17:38 +0900 |
commit | e273a1552e39b67e23de088b5ee663e6c16baccd (patch) | |
tree | 6170c5987887dba827cf00ad7d7a5cbf1d4a66a7 /sqlite3.go | |
parent | cleanup code (diff) | |
download | golite-e273a1552e39b67e23de088b5ee663e6c16baccd.tar.gz golite-e273a1552e39b67e23de088b5ee663e6c16baccd.tar.xz |
Fixed bug for loc parameter
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -423,13 +423,8 @@ func (s *SQLiteStmt) bind(args []driver.Value) error { } rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(p), C.int(len(v))) case time.Time: - if s.c.loc != nil { - b := []byte(v.In(s.c.loc).Format(SQLiteTimestampFormats[0])) - rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) - } else { - b := []byte(v.UTC().Format(SQLiteTimestampFormats[0])) - rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) - } + b := []byte(v.UTC().Format(SQLiteTimestampFormats[0])) + rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) } if rv != C.SQLITE_OK { return s.c.lastError() @@ -536,11 +531,18 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { return fmt.Errorf("error parsing %s value %d, %s", rc.decltype[i], val, err) } epoch := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) - dest[i] = epoch.Add(duration) + if rc.s.c.loc != nil { + dest[i] = epoch.Add(duration).In(rc.s.c.loc) + } else { + dest[i] = epoch.Add(duration) + } } else { - dest[i] = time.Unix(val, 0).Local() + if rc.s.c.loc != nil { + dest[i] = time.Unix(val, 0).In(rc.s.c.loc) + } else { + dest[i] = time.Unix(val, 0) + } } - case "boolean": dest[i] = val > 0 default: @@ -572,13 +574,13 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { switch rc.decltype[i] { case "timestamp", "datetime", "date": - zone := rc.s.c.loc - if zone == nil { - zone = time.UTC - } for _, format := range SQLiteTimestampFormats { - if timeVal, err = time.ParseInLocation(format, s, zone); err == nil { - dest[i] = timeVal + if timeVal, err = time.ParseInLocation(format, s, time.UTC); err == nil { + if rc.s.c.loc != nil { + dest[i] = timeVal.In(rc.s.c.loc) + } else { + dest[i] = timeVal + } break } } |