Page 1 of 1

quote characters in queries

Posted: 01.03.2010, 14:58
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.

Posted: 01.03.2010, 15:48
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.