Page 1 of 1

How to format a string parameter for comparison with MySQL like condition?

Posted: Wed Jul 08, 2015 7:02 pm
by jason7623981

What's the correct way to format a parameter for string comparison (i.e. a like statement in MySQL)?

My query looks like this:

select *
from a_database
where cost between 'min_price' and 'max_price'
and (title like '%keywords%'
or description like '%keywords%'
or caption like '%keywords%')
;

and doesn't work. However, this version of it works:

select *
from a_database
where cost between 'min_price' and 'max_price';

I tried a few variations of this, like :keywords, :?keywords, and messing around with {} and ', but I haven't hit pay dirt yet.

Thanks!

Update -- I also tried REGEXP instead of LIKE to no avail...


How to format a string parameter for comparison with MySQL like condition?

Posted: Thu Jul 09, 2015 10:35 am
by Pavel Zarudniy

Hi jason,
Please look at the documentation for MySQL - http://dev.mysql.com/doc/


How to format a string parameter for comparison with MySQL like condition?

Posted: Thu Jul 09, 2015 11:23 am
by jason7623981

?

I'm doing it correctly in terms of MySQL. I'm a SQL professional and the queries work fine from MySQL workbench they just don't work on Appery. Give it a try and you'll see what I mean.


How to format a string parameter for comparison with MySQL like condition?

Posted: Thu Jul 09, 2015 11:25 am
by jason7623981

The example I gave is valid SQL. Either this is a bug in ATI Express or you need some special input to identify the string parameter in string comparison. Try it yourself.


How to format a string parameter for comparison with MySQL like condition?

Posted: Thu Jul 09, 2015 1:35 pm
by Pavel Zarudniy

Please look at this screenshoot, query parameters mapped with :keyword
Image


How to format a string parameter for comparison with MySQL like condition?

Posted: Thu Jul 09, 2015 7:11 pm
by jason7623981

I'm sorry, I'm confused about what you're trying to show me

The code entered as in that screen shot does not produce results.

'%:keywords%'

is also not standard SQL. '%keywords%' would be standard MySQL SQL for a like statement. However I did already try '%:keywords%' and many other variations based on the documentation (which didn't cover this for API Express, so I was trying different variations from other parts of the documentation which didn't directly relate).

As far as I can tell, there's no way to do string comparisons in API Express. I believe we should escalate this to a bug report for your dev team.


How to format a string parameter for comparison with MySQL like condition?

Posted: Mon Jul 20, 2015 1:35 pm
by Alena Prykhodko

Hello,

Please try this SQL:

pre
select *
from a_database
where cost between 'min_price' and 'max_price'
and title like concat (:keywords, '%')
or description like concat (:keywords2, '%')
or caption like concat (:keywords3, '%') /pre

:keywords - parameters

This SQL selects password from Users where login -- like<---operator.