db icon indicating copy to clipboard operation
db copied to clipboard

All values are byte slices when using SQL builder with a map

Open abemedia opened this issue 5 years ago • 2 comments

I just recently migrated an old app from v1 to v4. In v1 I was using sqlutil.FetchRows(rows, &myMap) and this worked fine. Now I'm using sess.SQL().NewIterator(rows).All(&myMap) and this is resulting in every field being a byte slice, rather than it's correct type (i.e. int, string etc).

The issue is that in this particular part of the application it could connect to any DB so I cannot use structs. Is there a way to get upper/db to automatically use the correct type for a map[string]interface{}?

Edit: I changed only the sqlutil stuff back to using v1, but still getting the rows with v4 and it's still all bytes, so it seems to be happening elsewhere.

abemedia avatar Jan 01 '21 22:01 abemedia

Hello @abeMedia, do you think you can share the CREATE TABLE statement so we can write a test case? Also, what's the database and version you're using?

xiam avatar Jan 03 '21 05:01 xiam

I'll create a little test repo to demonstrate it.

abemedia avatar Jan 03 '21 13:01 abemedia