[DUG] Can dbExpress's TSQLQuery use ? as parameters?
Todd Martin
todd.martin.nz at gmail.com
Tue Feb 14 18:08:51 NZDT 2012
Are you currently setting the parameter values by index then?
Using regular expressions, search
\'(\w)+\s\=\s\?
and replace with
'$1 = :$1
so that
StringField =?,
becomes
StringField = :StringField,
It should take no time at all.
Todd.
> 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
>
>
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with Subject: unsubscribe
--
*Passion* is no substitute for *reason*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120214/8e9567f0/attachment.html
More information about the Delphi
mailing list