Comments (7)
MySQL itself isn't going to allow you to prepare the SHOW TABLES query. It
only permits parameters to be used for values, not identifiers. So I'm not
sure if this is helpful or just noise in this conversation, but I just
wanted to point out that your last sentence assumes something MySQL is not
going to allow.
On the other hand, the following is legal to prepare:
SHOW TABLES LIKE ?
from mysql.
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 SHOW CREATE {PROCEDURE | FUNCTION | EVENT | TABLE | VIEW}
ok for prepared statements? What's used as a parameter if not an identifier? Something along the lines of WHERE name LIKE ...
?
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 sql: statement expects 0 inputs; got 1
after
rows, err := db.Query("SHOW TABLES FROM ?", "mysql")
SHOW TABLES LIKE ?
didn't work for me, but SHOW TABLES
did. Still calls for USE ...
, though. It's not a big issue, but I hoped I could get along without tracking the current schema.
Still, thanks!
from mysql.
I get the following error in both cases, which seems completely fine to me:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '?' at line 1
Did you forget to check err
somewhere?
from mysql.
The error sql: statement expects 0 inputs; got 1
comes from database/sql/sql.go#1203. There is nothing we could do on driver side to change the error text.
I'm still wondering how you even got there without ignoring an err
, which should already be returned on Prepare(..)
from mysql.
I was able to demonstrate to Julien I could get the error without black magic or ignoring errors, but we can't prevent it.
from mysql.
Same issue here, solved by doing this:
stmt, err := mysql.Prepare("SELECT * FROM tags WHERE tag_name like ?")
rows, err := stmt.Query("%" + tagName + "%")
from mysql.
I got the same problem and it was because I had the ?
between quotes
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: sql: statement expects 0 inputs; got 2.
this was fine:
SELECT id, identifier FROM foobar WHERE id=? OR identifier=?
from mysql.
Related Issues (20)
- mysql 5.7 not supported? HOT 1
- g
- Rows.Scan fails with Scanner objects, but Row.Scan works ok with Scanner objects. HOT 3
- undefined: strings.Cut
- Installation command contains extra character HOT 2
- could you please support prepared sql for mysql5.7 and mysql8.0 user create/rename/drop etc...?
- busy buffer error after connection reset by peer HOT 7
- db.Close() does not close connection after query HOT 1
- OUT parameters for Stored Procedure Calls
- undefined: strings.Cut HOT 2
- ENUM and SET column types cannot be identified HOT 3
- 'go get' no longer supported HOT 1
- Please update documentation (installation - go get -u github.com/go-sql-driver/mysql fails for newer go versions) HOT 1
- BUG: resource don't release when db.Exec have error. HOT 8
- DSN: support - in database name HOT 2
- context deadline exceeded HOT 1
- panic in escapeStringBackslash HOT 3
- Empty result with max unsigned int value
- For some reason the data is not showing. HOT 1
- Cut a new v1.7.2 release HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql.