TZQuery Filter with * problem

The official tester's forum for ZeosLib 7.1. Ask for help, post proposals or solutions.
Post Reply
krzynio8
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.03.2014, 10:56

TZQuery Filter with * problem

Post by krzynio8 »

Hello!
I noticed that using asterisk as filter works fine only when I use * at the end of fileterd string ie. 'Test*'
When I use asterisk at the beginning ie. '*test' or use two asteriscs in the filter reults are not intuitive.

I tested on firebird db and sqlite db. Lets create any db and a table TABLE with one column COLUMN and fill it with values (1,2,1150,4311). Lets connect to db using a query 'select COLUMN from TABLE'. I tested using Zeoslib 7.1.2 TZConnection and TZQuery. Let's put TDataSource and TDBGrid components on a form and fill the Filter property using: grid.DataSource.Dataset.Filter = '11*'. The result will be correct: 1150. But when you put two wildcards '*11*' or put wildcard on the beginning of the string the result will be wrong: (1,2,1150,1143) instead of (1150, 1143).

I worked with Lazarus 0.9.3, 1.0, 1.1.99-pre, 1.2RC1 and 1.3.
With Zeos lib 6x, 7x
With SQL lite, MSSQL and Firebird
And in all cases I had the same problem with using wildcards, so I thought that problem must be somewhere in TDataSet component.
I published the problem on Lazasus forum but they anounced that this must be a problem with ZeosLib.

Regards,
Krzysztof
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Re: TZQuery Filter with * problem

Post by mdaems »

Hi,

I remember I recently wrote a quick (and therefore not complete) answer for this problem.
Have a look here : http://zeoslib.sourceforge.net/viewtopi ... 38&t=11288
I know, I ask some effort and hope you can fix it for us, but with our limited 'staff' this will take ages otherwise.

Mark
Image
miab3
Zeos Test Team
Zeos Test Team
Posts: 1309
Joined: 11.05.2012, 12:32
Location: Poland

Re: TZQuery Filter with * problem

Post by miab3 »

krzynio8,
grid.DataSource.Dataset.Filter = '11*' (or '*11*')
Strange that it works at all.

According to me it should be:

Code: Select all

DBGrid1.DataSource.DataSet.Filter := 'FName1 like ''*11*'''
And it works for me on Zeos7.2-alpha branches_ testing_r3109.

Michal
krzynio8
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.03.2014, 10:56

Re: TZQuery Filter with * problem

Post by krzynio8 »

Thank you very much for all.
The key was the module ZMatchPattern.
I just wanted to find a pattern in any place of a field value.
So, simple modification of IsMatch procedure solved my problem.

Code: Select all

function IsMatch(const Pattern, Text: string): Boolean;
begin
  if Pos(AnsiLowerCase(Pattern), AnsiLowerCase(Text))>0 then
  	Result := True
  else
  	Result := False;
  // Result := (Matche(Pattern, Text) = 1);
end; 
Thanks again and regards, Krzysztof
Post Reply