Alex
I've been using time.Time just a few seconds ago with go-sqlite3 and what I save in comes back the same way I've put it there.
I'm saving the time using time.Now().UTC(), if it matters.
I've been using time.Time just a few seconds ago with go-sqlite3 and what I save in comes back the same way I've put it there.
I'm saving the time using time.Now().UTC(), if it matters.
On Saturday, March 2, 2013 8:16:26 AM UTC-5, Archos wrote:
Hello,0) you insert a string value in a table.1) you want to retrieve a time.Time but:- the driver don't know the destination type (only the source/persisted type),- the driver should not return a string but a byte[] (mattn's driver seems to ignore this rule) (see driver.Rows.Next documentation),- there is no converter from byte[]/string to time.Time (see convertAssign).2) you want to retrieve a string but your code seems wrong (t is a copy of output in Args2).I've tried to make the second case work (with the help of the Scanner interface): http://play.golang.org/p/F0NUrRszyZRegards.
Hello,0) you insert a string value in a table.1) you want to retrieve a time.Time but:- the driver don't know the destination type (only the source/persisted type),- the driver should not return a string but a byte[] (mattn's driver seems to ignore this rule) (see driver.Rows.Next documentation),- there is no converter from byte[]/string to time.Time (see convertAssign).2) you want to retrieve a string but your code seems wrong (t is a copy of output in Args2).I've tried to make the second case work (with the help of the Scanner interface): http://play.golang.org/p/F0NUrRszyZRegards.On Sunday, March 3, 2013 11:25:27 AM UTC+1, Archos wrote:
I'm working on an experimental branch with time.Time support right now and I'm not sure what to return for the MySQL default value of DATE ("0000-00-00") and DATETIME ("0000-00-00 00:00:00") fields.
Any suggestions?
Hi Julien,
"Then, a possilbe solution for the driver MySQL would be to save time.Time using a SQL datatype for string."
Another option would be to store it like an int 64 using time.Unix (http://golang.org/pkg/time/#Time.Unix).
Then, at Scan, it is recovered the type Time using time.Unix (http://golang.org/pkg/time/#Unix)
The advantage will be the size, the con. is the conversion from int64 to Time
El domingo, 3 de marzo de 2013 00:15:26 UTC, Julien Schmidt escribió:
CREATE TABLE IF NOT EXISTS Posts(-- ...datetime TIMESTAMP, -- ...)Then when you read the value or write it, you use the time.Time type:type Post struct {// ...datetime time.Time // ...}When you set the time in the code, save it as UTC such that you don't need to worry about timezones when you get it back.func NewPost(author, content string) *Post {// ...p.datetime = time.Now().UTC() // ...return p}And then when you want to query it back from SQLite, using a prepared statement I did it such as:var author stringvar content stringvar datetime time.Timeerr = stmt.QueryRow(id).Scan(&author, &content, &datetime)And everything works just fine. I do it here: https://github.com/aybabtme/goblog-prototype/blob/master/db/post.go I'm much of a noob, I've been playing around with Go on weekends so my code might not be of top quality... however I don't have that problem you report with go-sqlite3.
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
* * *The "timestamp" type is hardcoded in the driver: