codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.55k stars 343 forks source link

time parsed error when make rows.Scan after stdlib SQL query with Go SDK #1238

Closed winterpi closed 2 years ago

winterpi commented 2 years ago

What happened Time value parsed incorrect: "54379-11-09 02:20:17.42 +0000 UTC"

What you expected to happen Should return readable time value, such as "2022-05-30 xx:xx:xx"

How to reproduce it (as minimally and precisely as possible)

  1. db := stdlib.OpenDB(opts)

  2. res, err := db.ExecContext(ctx, "CREATE TABLE IF NOT EXISTS table(id INTEGER AUTO_INCREMENT, time TIMESTAMP, PRIMARY KEY id)")

  3. rows, err := db.QueryContext(ctx, "select * from table")

  4. var id uint64 var time time.Time rows.Next() err = rows.Scan(&id, &time) if err != nil { panic(err) } fmt.Println("id: ", id, ", time: ", time)

  5. the result is : "id: 1 , time: 54379-11-09 02:20:17.42 +0000 UTC"

Additional info (any other context about the problem) with immudb v1.3.0

winterpi commented 2 years ago

I found that it's not OK for TIMESTAMP when using stdlib or generic SQL.

I debugged and found a strange problem as follow: (1). When a TIMESTAMP was inserted, it will call TimeToInt64() function in embedded/sql/timestamp.go to convert timestamp to int64, e.g. time.Now() --> 1654504712965537; (2) However, when it been saved into db, I got the value of 1654504712965537000 with sqlQuery. So it rendered error when make schema.RenderValue(1654504712965537000).

jeroiraz commented 2 years ago

thanks for reporting this @winterpi. We'll review it asap

winterpi commented 2 years ago

Sorry, it's my fault. I used the v1.3.0 go SDK, but with v1.2.1 immudb server. So the error occurred. After I changed the immudb server to V1.3.0, it's OK now.

@jeroiraz thank you for your reply.