-
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
improve error reporting for unpreparable statements #70
Comments
MySQL itself isn't going to allow you to prepare the SHOW TABLES query. It On the other hand, the following is legal to prepare: SHOW TABLES LIKE ? |
My last paragraph was misleading, by legitimate I only meant the query itself, not using it in a prepared statement (though I tried it this way at first). But that still leaves me wondering... If it is disallowed for identifiers, why is Concerning this issue, I only think the error message could and should be clearer, as it doesn't cause an error on prepare, only on execution. It's not even that bad when it is called as stmt, err := db.Prepare("SHOW TABLES FROM ?")
rows, err := stmt.Query("mysql") but it is very strange getting rows, err := db.Query("SHOW TABLES FROM ?", "mysql")
Still, thanks! |
I get the following error in both cases, which seems completely fine to me:
Did you forget to check |
The error |
I was able to demonstrate to Julien I could get the error without black magic or ignoring errors, but we can't prevent it. |
Same issue here, solved by doing this: stmt, err := mysql.Prepare("SELECT * FROM tags WHERE tag_name like ?") |
I got the same problem and it was because I had the stmt, err := db.Prepare("SELECT id, name FROM foobar WHERE id='?' OR name='?'")
checkErrFail(err)
err = q.QueryRow(slug, slug).Scan(&m.id, &m.name) error: this was fine: SELECT id, identifier FROM foobar WHERE id=? OR identifier=? |
This is a low-priority TODO, I'd like to wait until Brad's changes are in.
I got bitten by statments which can not be prepared. See MySQL documentation: SQL Syntax Allowed in Prepared Statements.
We should probably report errors in statments.go:Query(...) with
len(args) > 0
ifstmt.paramCount == 0
as an error caused by using prepared statements, right now it's a little confusing without background knowledge.Currently, the error looks like
sql: statement expects 0 inputs; got 1
.While checking this, I also spotted a missing closing brace in an error in packets.go.
I hit this while trying to use
which should be a legitimate way to explore the databases and tables on a server.
The text was updated successfully, but these errors were encountered: