quote characters in queries

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
PhillHS
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 23.05.2007, 14:11
Location: Coventry, UK

quote characters in queries

Post by PhillHS »

Hi,

In my app I have found that if I have a TDBEdit, that is linked to a field in a mysql table (via a TZQuery, and TZconnection).

If I type a string with a single quote in it such as "test'test" the field is correctly posted to the database (and the quote is escaped on the way, checked with an ZSQLmonitor).

However if I try and build the query with code such as :

Code: Select all

  WITH ZEditQuery DO
  BEGIN;
    Append;
    FieldByName(DBFChemCommonName).AsString:='test''test';
    ApplyUpdates;
  END;
The quote is not escaped and ApplyUpdates flags an SQL error.

Is there any way round this ?

Cheers.

Phill.
PhillHS
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 23.05.2007, 14:11
Location: Coventry, UK

Post by PhillHS »

Ok,

I've done some more investigation it turns out that setting the .asstring is quoting correctly, my errors where being caused by an un-quoted quote in a select statement.

So I've added a call to EncodeCString() around the passed in string.

Cheers.

Phill.
Post Reply