Lazarus

Free Pascal => Database => Topic started by: johnmc on January 12, 2020, 03:24:40 pm

Title: Filter syntax
Post by: johnmc on January 12, 2020, 03:24:40 pm
I have been trying to find some documenation regarding the syntax of the filter string used to filter a dataset, hitting F1 brings up only a brief description. Where can I find a complete description?

The best that I can come up with is the wiki https://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#Index.2Ffilter_on_strings (https://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#Index.2Ffilter_on_strings)

Was there some sort of software specification writen for this if so where would I find it?
Title: Re: Filter syntax
Post by: howardpc on January 12, 2020, 03:30:53 pm
Are you asking specifically about the Lazarus/FPC implementation of TDbf, or some other dataset descendant?
Title: Re: Filter syntax
Post by: johnmc on January 12, 2020, 03:48:45 pm
I am using Sqlite3, so that would be my preference if it makes any difference.
Title: Re: Filter syntax
Post by: GetMem on January 12, 2020, 06:35:06 pm
If you're using TSQLQuery, which is a TCustomBufDataset descendent,  the solution is quite simple: create an OnFilterRecord for the Query, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SQLQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
  2. begin
  3.   Accept := SQLQuery1.FieldByName('FIRSTNAME').AsString = 'John';
  4. end;
  5.  
The code is self explanatory I guess, if not please let us know.
Title: Re: Filter syntax
Post by: johnmc on January 12, 2020, 09:47:19 pm
GetMem I was using TDataSet.Filter and want more info on the format and syntax of the filter string.

Code: Pascal  [Select][+][-]
  1.       myFilter := 'Country = ' + QuotedStr(DBGrid1.SelectedField.AsString);
  2.       SQLQuery.filter := myFilter;
  3.       SQLQuery.Filtered := True;
  4.  

TinyPortal © 2005-2018