Skip to content
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

Failed scanning row for mysql with Option #24

Closed
yflau opened this issue Apr 4, 2023 · 4 comments
Closed

Failed scanning row for mysql with Option #24

yflau opened this issue Apr 4, 2023 · 4 comments

Comments

@yflau
Copy link

yflau commented Apr 4, 2023

For example

CREATE TABLE t (optional VARCHAR(64));

rows, err := db.Query("SELECT optional FROM t  LIMIT 1?")
for rows.Next() {
  var o mo.Option[string]
  if err := rows.Scan(&o); err != nil {
	  t.Errorf("Failed scanning row: %s", err.Error())
	  continue
  }
}

then will got Failed scanning row: sql: Scan error on column index 1, name "optional": failed to scan Option[T], and the reason is
that type of arg src of Scan is []uint8, and failed here when assert type is string, refer to sql.NullString, we can use the function sql.convertAssign to replace the driver.DefaultParameterConverter.ConvertValue to resolve it, but the convertAssign is private, and maybe won't be public(refer to golang/go#24258), so we can copy out the convertAssign and make some modification or write a new convert function? what do you think? Or have some other solution?

@samber
Copy link
Owner

samber commented Sep 25, 2023

Can you test with v1.9.0 please ?

@gsiffert
Copy link

@samber I just tried with both the v1.9.0 and the v1.11.0, both of them have the same issue.

@graineri
Copy link

Similar issue here as well. We are about to fork this repository and make use of the sql.convertAssign function.

@samber
Copy link
Owner

samber commented Jul 16, 2024

-> v1.13.0

@samber samber closed this as completed Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants