Page 1 of 1

TZQuery Filter with * problem

Posted: 30.03.2014, 11:26
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

Re: TZQuery Filter with * problem

Posted: 31.03.2014, 13:53
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

Re: TZQuery Filter with * problem

Posted: 01.04.2014, 09:30
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

Re: TZQuery Filter with * problem

Posted: 02.04.2014, 22:58
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