-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add ColumnTypeScanType to driver #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@ngocphuongnb, can you test this please? |
I'm gonna merge this as:
dest := make([]any, len(cols))
for rows.Next() {
cols, err := rows.ColumnTypes()
if err != nil {
return err
}
for i, c := range cols {
dest[i] = reflect.New(c.ScanType()).Interface()
}
err = rows.Scan(dest...)
if err != nil {
return err
}
} PR #197 would break this, be it because of "dynamic typing" or just NULLs in any column that's not |
With PR: If you call Once you start iterating through rows, you get types based on the values. Here, I'm only committing to this rule: the scan type must be able to scan the value. I do take into account the column type, but I make no claim to pick the "best" type (whatever that means), or "most specific" type, or whatever, to scan the value. Just that it can scan the value, and is not too stupid. If either these decisions turns out wrong, I'll tweak them. I'm pretty sure there's no right answer here, just heuristics. |
@ncruces Thank you for your great effort in making the decision and creating this PR. |
Thank you for your kind words! |
Fix #198.