single quote and Illegal filter expression

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
fisher
Posts: 2
Joined: Mon 01 Mar 2010 05:01
Contact:

single quote and Illegal filter expression

Post by fisher » Mon 01 Mar 2010 05:31

Good day.
I can not solve one problem.
I have a TMyQuery on a form. In database I have some records 'some_data' (with quotes) and want to find them.
When I set propery

Code: Select all

Filter = 'CATEGORY_NAME = '''some_data'''';

and then

Code: Select all

Filtered = true;
I get exception "Illegal filter expression".

When I use MySQL syntax, I set

Code: Select all

FilterSQL = '`CATEGORY_NAME` = \some_data\';
all is normally filtered.

How I must set Filter property to filter data with single quotes?
MyDAC version: 5.90.0.55

Falcon
Devart Team
Posts: 19
Joined: Tue 02 Feb 2010 10:40

Post by Falcon » Mon 01 Mar 2010 12:41

Use following code:

Code: Select all

Filter := 'CATEGORY_NAME = ''some_data''';
instead of

Code: Select all

Filter = 'CATEGORY_NAME = '''some_data'''';

fisher
Posts: 2
Joined: Mon 01 Mar 2010 05:01
Contact:

Post by fisher » Wed 03 Mar 2010 02:47

Thanks for the answer, but your variant too raises Illegal filer Expression.
It's works only if I type (I'm checking in Object Inspector by changing property Filter and then setting property Filtered in true)

Code: Select all

CATEGORY_NAME = 'some_data'
but it filtered by some_data not by 'some_data'.

How correctly to shield single quotes for the Filter property?

Falcon
Devart Team
Posts: 19
Joined: Tue 02 Feb 2010 10:40

Post by Falcon » Thu 04 Mar 2010 10:44

Use the following designtime Filter property value

Code: Select all

CATEGORY_NAME = "''some_data''".
In runtime you can use the following code

Code: Select all

Filter := 'CATEGORY_NAME = "''''some_data''''"';.

Post Reply