Page 1 of 1

Access to SQL query text after replacing macros?

Posted: Fri 27 Jul 2012 11:34
by Asti
Hello,
I am using the UniDAC component in RAD-Studio 2010 (Delphi) and currently started to implement macros for my database application which must run on Oracle as well as SQL Server.
Now my question:
Is there nay function to return the final SQL string as it is executed by the database (i.e., after macros have been rplaced by the provider specific tokens)? I need such a possibility because I have to trace all sql queries in a log file.

Example:

Code: Select all

Query1.SQL.text:='select {IsNull}(MyColumn,MyDefault) from MyTable';
In this case I would like to get access to the replaced string, e.g. in Oracle:

Code: Select all

'select NVL(MyColumn,MyDefault) from MyTable'
Do you have any idea, how to solve this?
Best regards,
Asti

Re: Access to SQL query text after replacing macros?

Posted: Fri 27 Jul 2012 11:56
by AndreyZ
Hello,

You should use the FinalSQL property that is used to return SQL text with all changes performed by the AddWhere, SetOrderBy, and FilterSQL methods, and with expanded macros. For example:

Code: Select all

UniQuery1.SQL.text:='select &IsNull(MyColumn,MyDefault) from MyTable';
UniQuery1.MacroByName('IsNull').AsString := 'NVL';
ShowMessage(UniQuery1.FinalSQL);