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

How to prepared statement query at limit and offset

Open M1n007 opened this issue 3 years ago • 14 comments

im trying to querying prepared statement at limit and offset but error

Success image

Error image

M1n007 avatar Aug 18 '22 01:08 M1n007

From the error text it looks like the problem is in the sql query. Could you show your .execute() or prepare() arguments?

sidorares avatar Aug 18 '22 02:08 sidorares

From the error text it looks like the problem is in the sql query. Could you show your .execute() or prepare() arguments?

image

this statement and values image

if limit and offset not prepared statement image

M1n007 avatar Aug 18 '22 02:08 M1n007

you have 5 parameters in the first example and only 2 in a second while you are saying you replaced 2 placeholders with hardcoded text

sidorares avatar Aug 18 '22 02:08 sidorares

you have 5 parameters in the first example and only 2 in a second while you are saying you replaced 2 placeholders with hardcoded text

wait i miss to show 3 parameters

M1n007 avatar Aug 18 '22 03:08 M1n007

oh right, I see you also removed like ? from the second example so it adds up

sidorares avatar Aug 18 '22 03:08 sidorares

oh right, I see you also removed like ? from the second example so it adds up

yes right

M1n007 avatar Aug 18 '22 03:08 M1n007

I think the error is somewhere in the and concat part. Try to put it on a separate line ( and also add a space and ?and => and ? ) and :

#...start of your query
and (createdDate between ? and ?)
and (concat(...) like ?)
#... order by + limit + offset

sidorares avatar Aug 18 '22 03:08 sidorares

I think the error is somewhere in the and concat part. Try to put it on a separate line ( and also add a space and ?and => and ? ) and :

#...start of your query
and (createdDate between ? and ?)
and (concat(...) like ?)
#... order by + limit + offset

this sample with 3 parameter without limit and offset image

this if 5 parameter include limit and offset prepared statement image

M1n007 avatar Aug 18 '22 04:08 M1n007

without concat error image

without concat success image

M1n007 avatar Aug 18 '22 04:08 M1n007

thanks for help before @sidorares

M1n007 avatar Aug 18 '22 04:08 M1n007

I think the error is somewhere in the and concat part. Try to put it on a separate line ( and also add a space and ?and => and ? ) and :

#...start of your query
and (createdDate between ? and ?)
and (concat(...) like ?)
#... order by + limit + offset

this sample with 3 parameter without limit and offset image

this if 5 parameter include limit and offset prepared statement image

also if using namedPlaceHolder

Success image

Error image

M1n007 avatar Aug 18 '22 08:08 M1n007

Try in dbeaver success image

M1n007 avatar Aug 18 '22 09:08 M1n007

I'm not sure if dbeaver is using real server side prepared statements or does client side query building. More real test would be to do PREPARE command in mysql command line - https://dev.mysql.com/doc/refman/8.0/en/prepare.html

sidorares avatar Aug 18 '22 23:08 sidorares

still, can u helpme ?

M1n007 avatar Aug 19 '22 02:08 M1n007