Is there any way to intercept every SQL that passes through a connection and change it?
Is there any way to intercept every SQL that passes through a connection and change it?
For example:
I have a TQuery with "Select First 1 * From TABLE";
I want to intercept it and edit the SQL to "Select * From TABLE Where ROWNUM <= 1"
For example:
I have a TQuery with "Select First 1 * From TABLE";
I want to intercept it and edit the SQL to "Select * From TABLE Where ROWNUM <= 1"
- dll inject into process
ReplyDelete- create db proxy
You don't say what connection you use, but
ReplyDeletehttp://theroadtodelphi.wordpress.com/2010/02/21/build-your-own-profiler-using-ado/ describes how to write an interceptor for ADO.
Lars Fosdal We use AnyDAC. I am reading that right now, thanks.
ReplyDeleteLars Fosdal TADConnection doesn't have the events necessary to implement that solution :\
ReplyDeleteIngo Wagner Jr. as far as I know(and I don't know much about it), AnyDac should have a SQL Monitor component.
ReplyDeleteOr am I missing something?
Regards,
A
I had a look at FireDAC and it looks like TADConnection uses it's ConnectionIntf to create the SQL, which again is retrieved from the ADPhysManager and another property defines what TADPhysCommandKind to use. Perhaps it is possible to inject something through there?
ReplyDeleteIf you have access to the original source code, you can create a new class inherited from tquery something like tlogquery and override required methods. Then you replace old tquery declaration with the new one tlogquery
ReplyDeleteRafa Botero - Unfortunately, a lot of these methods are not virtual - at least not in FireDAC.
ReplyDeleteHmm... that interceptor thing has promise!
ReplyDeleteTranslate "select * from inventory"
to
insert into accountspayable (accountid, amt) values ((select id from accounts where firstname='kevin' and lastname='mccoy'), 1000.0)
I can retire! :-)