Modify SQL text on the fly

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Botaniil
Posts: 1
Joined: Fri 15 Feb 2019 15:30

Modify SQL text on the fly

Post by Botaniil » Fri 15 Feb 2019 15:36

Hi,

i have a lot of old delphi codes like this:

SomeQuery.SQL.Text:='select Name from SomeTable where Version=:Version ';
SomeQuery.ParamByName('Version').asString:='1';
SomeQuery.Open;

now application adopted for work with PostreSQL via Unidac and code should like this:

'select "Name" from SomeTable where "Version"=:"Version" ';


So, please, help me to choose appropriate TUniQuery methods (to override) for change query text on the fly
There are a variety of places: BeforeOpen, AssembleSQL, InternalOpen, Macros....TUniQuery.SQL or TUniQuery.FCommand.SQL..etc

And how to synchronize parameters (or query params parsing) for updated quoted identifiers?

FCS
Posts: 169
Joined: Sat 23 Feb 2013 18:46

Re: Modify SQL text on the fly

Post by FCS » Tue 19 Feb 2019 12:42

Hi,

Try use:

- Prepare method before setting parameters and Open
- 'select "Name" from SomeTable where "Version"=:Version ';

PostgreSQL dislikes big letters in names, but supports them by "".


Regards
Michal

MaximG
Devart Team
Posts: 1469
Joined: Mon 06 Jul 2015 11:34

Re: Modify SQL text on the fly

Post by MaximG » Fri 22 Feb 2019 12:31

Please explain the reason of the neccessity for quoting field and parameter names as it is shown in the query you provided.
You can change the text of a SQL query by referring to the 'SomeQuery.SQL.Text' property. Explain, please, in what cases you need to use such changes in your projects.

Post Reply