go-sql-driver/mysql

mysql error `ERROR 3141` is not cathed in db.query()

sora91s opened this issue · 7 comments

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

image

but when i use query, no error is reported

image

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

no error log but it should be error

Configuration

Driver version (or git SHA):

Go version: run go version in your console

Go 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

No error while sending query.
You need to read result and check error.

image

no result in rows, what should i do?

You don't call rows.Err() nor rows.Close().