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

db.exec select failed #138

Open
ningmonguo opened this issue Jun 4, 2024 · 0 comments
Open

db.exec select failed #138

ningmonguo opened this issue Jun 4, 2024 · 0 comments

Comments

@ningmonguo
Copy link

`package sqlite_db

import (
"database/sql"
"fmt"
"github.com/glebarez/sqlite"
_ "github.com/mattn/go-sqlite3"
"gorm.io/gorm"
"log"
)

func Sqlite() {
dial := sqlite.Open("sqlite3:example.db")

db, err := gorm.Open(dial)
if err != nil {
	fmt.Println("open dial err, err: ", err)
	return
}

rs, err := db.Exec("select name, age from user").Rows()
if err != nil {
	log.Fatal(err)
	return
}
defer rs.Close()
for rs.Next() {
	var name string
	var age int
	err := rs.Scan(&name, &age)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(name, age)
}

}
`

2024/06/04 14:12:04 E:/Study/Goproject/src/test02/sqlite_db/sqlite.go:38 SQL logic error: unrecognized token: "" (1) [0.000ms] [rows:-] SELECT * FROM
2024/06/04 14:12:04 SQL logic error: unrecognized token: "`" (1)

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

1 participant