jason7623981
Posts: 0
Joined: Sun Jul 05, 2015 7:33 pm

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

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...

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

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

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

jason7623981
Posts: 0
Joined: Sun Jul 05, 2015 7:33 pm

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

?

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.

jason7623981
Posts: 0
Joined: Sun Jul 05, 2015 7:33 pm

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

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.

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

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

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

jason7623981
Posts: 0
Joined: Sun Jul 05, 2015 7:33 pm

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

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.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

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

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.

Return to “Issues”