node-mariasql
node-mariasql copied to clipboard
LIMIT can't be provided in a prepared statement
When you have a prepared statement like
var q = c.prepare("SELECT * FROM my_tbl LIMIT :limit"); q({limit: 1}, ...);
it throws a 1064: Error 1064: You have an error in your SQL syntax
Yeah this is expected currently, as the placeholders are replaced with quoted values (except for null
/undefined
of course).
Thanks for the confirmation. Is this slated to be fixed soon?
Short of writing an SQL query parser or switching to real/server-side prepared statements, I don't know how this can be fixed to (elegantly) support non-quoted values.
Not sure if this will work, but can't you put non-quoted values by default. So, when someone wants a string, they'll wrap it in '
and place it?
Going off of what @eknath-iyer said, couldn't you do a simple typeof item
check and add quotes if typeof item === "string"
and/or not if typeof item === "number"
?
Pull request https://github.com/mscdex/node-mariasql/pull/153 should fix this issue (and other integer-related ones).
Tested locally, would be happy to have any comments.
I also faced this this and proposed fix https://github.com/mscdex/node-mariasql/pull/189 before noticing there was already a pending PR.
Merge whichever you want, but please let's have this resolved.
Since 1 May 2015 and still not fixed ...