Recent

Author Topic: [SOLVED] SQLite3 Zeos Search  (Read 1711 times)

Pe3s

  • Jr. Member
  • **
  • Posts: 98
[SOLVED] SQLite3 Zeos Search
« on: November 16, 2021, 09:31:12 pm »
Hello, I have such a problem with the search. The plan is that after typing in edit, the database is to display the matching names and after deleting it, display everything.
Code: Pascal  [Select][+][-]
  1.  ZQuery1.Close;
  2.   ZQuery1.SQL.Clear;
  3.   ZQuery1.SQL.Add('select * from testtbl WHERE Imie='+QuotedStr(Edit5.Text));
  4.   ZQuery1.ExecSQL;  

I can ask for help


Thank you for all your help.
Regards
« Last Edit: November 17, 2021, 05:24:21 pm by Pe3s »

korba812

  • Full Member
  • ***
  • Posts: 229
Re: SQLite3 Zeos Search
« Reply #1 on: November 16, 2021, 10:28:27 pm »
Try
Code: Pascal  [Select][+][-]
  1. ZQuery1.Open;
instead
Code: Pascal  [Select][+][-]
  1. ZQuery1.ExecSQL;

dseligo

  • Sr. Member
  • ****
  • Posts: 446
Re: SQLite3 Zeos Search
« Reply #2 on: November 17, 2021, 12:34:01 am »
As korba812 said, but also:

Code: Pascal  [Select][+][-]
  1.   ZQuery1.Close;
  2.   ZQuery1.SQL.Clear;
  3.   ZQuery1.SQL.Add('select * from testtbl';
  4.   If Edit5.Text <> '' then
  5.     ZQuery1.SQL.Add('WHERE Imie='+QuotedStr(Edit5.Text));
  6.   ZQuery1.Open;

Pe3s

  • Jr. Member
  • **
  • Posts: 98
Re: SQLite3 Zeos Search
« Reply #3 on: November 17, 2021, 07:11:58 am »
Unfortunately it does not work

Zvoni

  • Hero Member
  • *****
  • Posts: 838
Re: SQLite3 Zeos Search
« Reply #4 on: November 17, 2021, 08:32:24 am »
Use parameters.
another thing might be that you're comparing equality, meaning it has to be an exact match incl. Case
Maybe use "LIKE" instead of "="
Don't forget the wildcards
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

GetMem

  • Hero Member
  • *****
  • Posts: 3646
Re: SQLite3 Zeos Search
« Reply #5 on: November 17, 2021, 08:45:04 am »
@Pe3s

Quote
Unfortunately it does not work
What exactly does not work? Please be more specific.


PS: See attached project. On Windows you need sqlite3.dll. On Linux please change cnMain.LibraryLocation(form create).


Pe3s

  • Jr. Member
  • **
  • Posts: 98
Re: SQLite3 Zeos Search
« Reply #6 on: November 17, 2021, 10:20:45 am »
does not search data

wp

  • Hero Member
  • *****
  • Posts: 9170
Re: SQLite3 Zeos Search
« Reply #7 on: November 17, 2021, 10:43:28 am »
For me dseligo's code is working - see attachment.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

GetMem

  • Hero Member
  • *****
  • Posts: 3646
Re: SQLite3 Zeos Search
« Reply #8 on: November 17, 2021, 11:53:40 am »
@wp

Quote
For me dseligo's code is working - see attachment.
Yes it works, but if I understood the OP correctly, he wants to change the list on each keypress. Similar to the Object Inspector's Properties filter.
Also closing then (re)opening the query on each search might not be optimal on large tables. This is why I choose the Filtered/OnFilterRecord property and event.

Zvoni

  • Hero Member
  • *****
  • Posts: 838
Re: SQLite3 Zeos Search
« Reply #9 on: November 17, 2021, 12:13:00 pm »
@wp

Quote
For me dseligo's code is working - see attachment.
Yes it works, but if I understood the OP correctly, he wants to change the list on each keypress. Similar to the Object Inspector's Properties filter.
Also closing then (re)opening the query on each search might not be optimal on large tables. This is why I choose the Filtered/OnFilterRecord property and event.
Look at my post #4
He checks equality
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018