diff options
author | mattn <mattn.jp@gmail.com> | 2012-12-26 10:01:39 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2012-12-26 10:01:39 +0900 |
commit | f86c8f208da38aa635edd02286b35f5d71543045 (patch) | |
tree | a49ac0cd07b950db23a988ea2d6f337c92bf500d /sqlite3.go | |
parent | add example code using bulk insert. (diff) | |
download | golite-f86c8f208da38aa635edd02286b35f5d71543045.tar.gz golite-f86c8f208da38aa635edd02286b35f5d71543045.tar.xz |
check destination type whether it's *time.Time or not.
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -324,20 +324,27 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { case C.SQLITE_TEXT: var err error s := C.GoString((*C.char)(unsafe.Pointer(C.sqlite3_column_text(rc.s.s, C.int(i))))) - if rc.decltype[i] == "timestamp" || rc.decltype[i] == "datetime" { - dest[i], err = time.Parse(SQLiteTimestampFormat, s) - if err != nil { - dest[i], err = time.Parse(SQLiteDateFormat, s) + + switch dest[i].(type) { + case *time.Time: + if rc.decltype[i] == "timestamp" || rc.decltype[i] == "datetime" { + dest[i], err = time.Parse(SQLiteTimestampFormat, s) if err != nil { - dest[i], err = time.Parse(SQLiteDatetimeFormat, s) + dest[i], err = time.Parse(SQLiteDateFormat, s) if err != nil { - dest[i] = s + dest[i], err = time.Parse(SQLiteDatetimeFormat, s) + if err != nil { + dest[i] = s + } } } + } else { + dest[i] = s } - } else { + default: dest[i] = s } + } } return nil |