node-mariasql icon indicating copy to clipboard operation
node-mariasql copied to clipboard

LIMIT can't be provided in a prepared statement

Open ek-nath opened this issue 9 years ago • 8 comments

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

ek-nath avatar May 01 '15 08:05 ek-nath

Yeah this is expected currently, as the placeholders are replaced with quoted values (except for null/undefined of course).

mscdex avatar May 01 '15 08:05 mscdex

Thanks for the confirmation. Is this slated to be fixed soon?

ek-nath avatar May 04 '15 22:05 ek-nath

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.

mscdex avatar May 05 '15 15:05 mscdex

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?

ek-nath avatar May 06 '15 22:05 ek-nath

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"?

Shadow53 avatar Mar 19 '16 05:03 Shadow53

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.

prog893 avatar Jul 03 '16 10:07 prog893

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.

krizalys avatar Sep 02 '17 20:09 krizalys

Since 1 May 2015 and still not fixed ...

oom- avatar Aug 08 '18 22:08 oom-