Recent

Author Topic: [SOLVED] Zeos SQL querry problem  (Read 6136 times)

samto

  • Newbie
  • Posts: 5
[SOLVED] Zeos SQL querry problem
« on: September 06, 2012, 12:46:19 pm »
Hi all,

I am a newbie in using Zeos components.  I need to make a simple database filtering, using sql querries.

Here is a sample syntax:

ZQuery1.SQL.Clear;
ZQuery1.SQL.Text := Edit1.text;
ZQuery1.Open;

I tried also ZQuery1.ExecSQL procedure but without success ... and without error message. Simply - it does nothing.  There is probably some variable not corectly setted, but I dont know which one ... I tried many combinations.

Can you help me, or better, can you provide me some simple example?

Thanks for a help and have a nice day.
« Last Edit: September 07, 2012, 07:53:09 am by samto »

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Zeos SQL querry problem
« Reply #1 on: September 06, 2012, 02:22:24 pm »

Here is a simple filtering mechanism, change <database field> to your database field that you want to be filtered.
Regards.

Code: [Select]
      filter_title:=Edit1.Text;
      ZTable1.DisableControls;
      ZTable1.Filtered:=False;
      ZTable1.Filter:='<database field> LIKE '+QuotedStr('*'+filter_title+'*');
      ZTable1.Filtered:=True;
      ZTable1.EnableControls;

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: Zeos SQL querry problem
« Reply #2 on: September 06, 2012, 03:13:59 pm »
Be careful about using QuotedStr to escape SQL strings. If the string contains \' and the database engine uses backslash escape the string passed will be \'' and will fail.

'a single quote \' in a string' ---> 'a single quote \'' in a string'
DB engine will escape to  'a single quote ' in a string'   which is a parsing error.

MSSQL does not recognize backslash quoting and it can be turned off in PostgreSQL. AFAIK all other DB engines use backslash escaping.
« Last Edit: September 06, 2012, 03:22:16 pm by goodname »

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Zeos SQL querry problem
« Reply #3 on: September 06, 2012, 09:48:39 pm »

Single punctuation or double matter, as @godname says, but mostly you can try it yourself.
@Thanks goodname for additional information.
Regards.

samto

  • Newbie
  • Posts: 5
Re: [SOLVED] Zeos SQL querry problem
« Reply #4 on: September 07, 2012, 07:56:29 am »
Thank you for your help, it works well (unfortunatelly very slow, but it is another problem)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Zeos SQL querry problem
« Reply #5 on: September 07, 2012, 07:59:05 am »
AFAIK all other DB engines use backslash escaping.

Does a double backslash cancel the escaping procedure on those that do?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: [SOLVED] Zeos SQL querry problem
« Reply #6 on: September 07, 2012, 03:02:13 pm »
AFAIK all other DB engines use backslash escaping.

Does a double backslash cancel the escaping procedure on those that do?

I don't know. The best option here is to just try various string escape combinations to see what works and what throws errors.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Zeos SQL querry problem
« Reply #7 on: September 08, 2012, 02:50:58 pm »
Be careful about using QuotedStr to escape SQL strings. If the string contains \' and the database engine uses backslash escape the string passed will be \'' and will fail.

'a single quote \' in a string' ---> 'a single quote \'' in a string'
DB engine will escape to  'a single quote ' in a string'   which is a parsing error.

MSSQL does not recognize backslash quoting and it can be turned off in PostgreSQL. AFAIK all other DB engines use backslash escaping.
Trying to insert quotes by escaping with backslash fails on Firebird 2.5
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018