Page 1 of 1

Modify SQL text on the fly

Posted: Fri 15 Feb 2019 15:36
by Botaniil
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?

Re: Modify SQL text on the fly

Posted: Tue 19 Feb 2019 12:42
by FCS
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

Re: Modify SQL text on the fly

Posted: Fri 22 Feb 2019 12:31
by MaximG
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.