Access to SQL query text after replacing macros?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Asti
Posts: 1
Joined: Fri 27 Jul 2012 10:57

Access to SQL query text after replacing macros?

Post by Asti » Fri 27 Jul 2012 11:34

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

AndreyZ

Re: Access to SQL query text after replacing macros?

Post by AndreyZ » Fri 27 Jul 2012 11:56

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);

Post Reply