Recent

Author Topic: ZQuery Filter Problem..  (Read 3294 times)

FezaCakir

  • New member
  • *
  • Posts: 8
ZQuery Filter Problem..
« on: September 12, 2016, 11:16:32 am »
Hi everybody.

The Code is:

with QXList do begin
  FilterOptions:=[foCaseInsensitive];
  Filtered:=False;
  Filter:='XName like ''%'+edSearch.Text+'%''';
  Filtered:=True;
 end;

It doesn't work.

Do I wrong something?
Thanks..                                             

FezaCakir

  • New member
  • *
  • Posts: 8
Re: ZQuery Filter Problem..
« Reply #1 on: September 12, 2016, 11:26:12 am »
I fixed and it works.
I replaced % with *.

with QXList do begin
  FilterOptions:=[foCaseInsensitive];
  Filtered:=False;
  Filter:='XName like ''*'+edSearch.Text+'*''';
  Filtered:=True;
 end;

btr0001

  • New member
  • *
  • Posts: 8
Re: ZQuery Filter Problem..
« Reply #2 on: October 02, 2024, 11:13:47 am »
How did you gess to use * instead of &?

af0815

  • Hero Member
  • *****
  • Posts: 1392
Re: ZQuery Filter Problem..
« Reply #3 on: October 02, 2024, 12:01:46 pm »
The useable wildcard depends on your DB. Please read the doc for your used DB. One short hint here https://www.w3schools.com/sql/sql_wildcards.asp
regards
Andreas

Sieben

  • Sr. Member
  • ****
  • Posts: 374
Re: ZQuery Filter Problem..
« Reply #4 on: October 02, 2024, 12:16:25 pm »
@FezaCakir: I suggest using QuotedStr in your Filter expression instead of multiple single quotes:

Code: Pascal  [Select][+][-]
  1.   Filter := 'XName = ' + QuotedStr('*'+edSearch.Text+'*');

Makes it more readable and avoids errors. And please use the Insert Code button to format code parts of your messages.

@af0815: SQL dialect doesn't matter here as TDataSet.Filter is purely a client side operation and doesn't reach out to the DBMS.

Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

dseligo

  • Hero Member
  • *****
  • Posts: 1522
Re: ZQuery Filter Problem..
« Reply #5 on: October 02, 2024, 12:25:36 pm »
How did you gess to use * instead of &?

Probably not a guess.
Look at documentation: https://www.freepascal.org/docs-html/fcl/db/tdataset.filteroptions.html

rvk

  • Hero Member
  • *****
  • Posts: 6758
Re: ZQuery Filter Problem..
« Reply #6 on: October 03, 2024, 12:51:27 pm »
I'm not familiar with TZQuery but if you want to use LIKE (and other SQL server related filter structures) you might want to use ServerFilter instead of Filter. Filter is executed on client side while ServerFilter is sent to the server along with the SQL (in fact the SQL is changed on the fly then).

https://www.freepascal.org/docs-html/fcl/sqldb/tsqlquery.serverfilter.html

I don't know if TZQuery has a ServerFilter though.

 

TinyPortal © 2005-2018