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

Scan: unsupported type reflect.Value. parameter is not a valid reference #523

Open
hjlp20150803 opened this issue Mar 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hjlp20150803
Copy link

What version of Chai are you using?

github.com/chaisql/chai v0.16.0

What did you do?

package main

// import chai as a blank import
import (
"database/sql"
"log"

"github.com/chaisql/chai/driver"

)

type User struct {
Id int
Name string
Age int
}

func main() {

// Create a sql/database DB instance
db, err := sql.Open("chai", "mydb")
if err != nil {
	log.Fatal(err)
}
defer db.Close()
if _, err = db.Exec(`

CREATE TABLE user (
id int,
name TEXT ,
age int
)
`); err != nil {
log.Println("exec.create :", err)
}

if _, err = db.Exec(`INSERT INTO user (id, name, age) VALUES (?, ?, ?)`, 20, "foo", 40); err != nil {
	log.Println("exec.INSERT :", err)
}

if row := db.QueryRow("SELECT id, name, age, address FROM user WHERE age >= ?", 18); row != nil {

	var u User
	if err = row.Scan(driver.Scanner(&u)); err == nil {
		log.Println("u:", u)
	} else {
		log.Println("Scan:", err)
	}
}

}

What did you expect to see?

read out data in db into user

What did you see instead?

2024/03/13 20:25:03 Scan: unsupported type reflect.Value. parameter is not a valid reference

@hjlp20150803 hjlp20150803 added the bug Something isn't working label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant