[DUG] Can dbExpress's TSQLQuery use ? as parameters?

Robo robo555 at gmail.com
Tue Feb 14 17:52:29 NZDT 2012


We've porting code to Delphi XE2, and need to change our data access
components from third party ODBCExpress which is no longer in business, to
dbExpress's TSQLQuery.

We have parametrized SQL query such as:

    sSQL :=
      'UPDATE ZTestData SET '+
      ' StringField =?, '+
      ' IntField = ?, '+
      ' DecimalField = ?, '+
      ' BooleanField = ?, '+
      ' DateTimeField = ?, '+
      ' TextField = ? '+
      ' WHERE UniqueID = 3';

if we use the following code:

var
  qry:TSQLQuery;
begin
  qry.Close;
  qry.SQL.Text := sSQL;
  ShowMessage(IntToStr(qry.Params.Count));
end;

It returns 0, so we're unable to get the bindings working, but if we change
sSQL to:

    sSQL :=
      'UPDATE ZTestData SET '+
      ' StringField =:Param1, '+
      ' IntField = :Param2, '+
      ' DecimalField = ?, '+
      ' BooleanField = ?, '+
      ' DateTimeField = ?, '+
      ' TextField = ? '+
      ' WHERE UniqueID = 3';

It returns 2.

It's going to be a big hassle to change all the SQL queries to the new
parameter syntax. Is there anyway for the TSQLQuery to recognize the ?
syntax?

I see that DBXCommon.TDBXCommand uses the ? syntax:

http://www.andreanolanusse.com/en/parameterized-queries-with-dbexpress-dbx-framework/

But it would mean throwing away our code that uses TSQLQuery. What's the
quickest/easiest way to resolve this? What's the difference between
TSQLQuery and TDBXCommand anyway, in terms of what's relevant to me?

Robo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120214/68d632fe/attachment.html 


More information about the Delphi mailing list