-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
mysql error ERROR 3141
is not cathed in db.query()
#1622
Comments
No error while sending query. |
You don't call rows.Err() nor rows.Close(). |
@methane Can you help me solve it? |
Calling it before calling From the docs of
Example: package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
func main() {
log.SetFlags(0)
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", "root", "root", "127.0.0.1", 3306, "test"))
if err != nil {
log.Fatalf("error in sql.Open: %s", err)
}
defer db.Close()
rows, err := db.Query(`SELECT JSON_TYPE('[1,2,3')`)
if err != nil {
log.Fatalf("error in db.Query: %s", err)
}
defer rows.Close()
for rows.Next() {
log.Println("scanned row")
var dest any
if err := rows.Scan(&dest); err != nil {
log.Fatalf("error in rows.Scan: %s", err)
}
}
if err := rows.Err(); err != nil {
log.Fatalf("error in rows.Err: %s", err)
}
} Output:
You cal also use // ...
row := db.QueryRow(`SELECT JSON_TYPE('[1,2,3')`)
var dest any
if err := row.Scan(&dest); err != nil {
log.Fatalf("error in rows.Scan: %s", err)
}
} |
thanks |
Issue description
mysql error
ERROR 3141
is not cathed in query()sql: select JSON_TYPE('[1,2,3');
'[1,2,3' is not a json str, so So an error will be reported for JSON_TYPE
but when i use query, no error is reported
Example code
func main() {
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", "user", "pswd", "127.0.0.1", 3306, "database"))
if err != nil {
panic(err)
}
sqlStr := "select JSON_TYPE('[1,2,3');"
err = query(db, sqlStr)
fmt.Printf("error: %v", err)
}
func query(db *sql.DB, sqlStr string) error {
_, err := db.Query(sqlStr) // ignore_security_alert
if err != nil {
fmt.Println(fmt.Sprintf("db query err: %s, sql:%s", err.Error(), sqlStr))
panic(err)
}
return nil
}
Error log
Configuration
Driver version (or git SHA):
Go version: run
go version
in your consoleGo 1.21.3
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
MySQL 8.0/5.7
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
MacOs
The text was updated successfully, but these errors were encountered: