Commit f88e7c6c authored by gwenn's avatar gwenn

Add support to Time type in Bind methods.

Unix time has been choosen as default storage format.
parent 9c5a8b15
......@@ -18,6 +18,17 @@ func TestJulianDay(t *testing.T) {
}
}
func TestBind(t *testing.T) {
db := open(t)
defer db.Close()
var delta int
err := db.OneValue("SELECT CAST(strftime('%s', 'now') AS NUMERIC) - ?", &delta, time.Now())
checkNoError(t, err, "Error reading date: %#v")
if delta != 0 {
t.Errorf("Delta between Go and SQLite timestamps: %d", delta)
}
}
func TestScan(t *testing.T) {
db := open(t)
defer db.Close()
......
......@@ -691,10 +691,10 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
p = &value[0]
}
rv = C.my_bind_blob(s.stmt, i, unsafe.Pointer(p), C.int(len(value)))
/*
case time.Time: // At least three representations are possible: string (YYYY-MM-DDTHH:MM:SS.SSS), int64 (unix time), float64 (julian day)
rv = C.sqlite3_bind_text()
*/
case time.Time: // At least three representations are possible: string (YYYY-MM-DD HH:MM:SS.SSS), int64 (unix time), float64 (julian day)
// rv = C.my_bind_text(s.stmt, i, value.format("2006-01-02 15:04:05.000"))
rv = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(value.Unix()))
// rv = C.sqlite3_bind_double(s.stmt, i, JulianDay(value))
case ZeroBlobLength:
rv = C.sqlite3_bind_zeroblob(s.stmt, i, C.int(value))
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment