Capture SQL execution results

Capture SQL execution results

Postby charliemango » Tue 29 Nov 2016 10:31

Hello, I am wondering if it is possible to gain access to the result set at some level outside of where a linq query is written. For example, I can monitor the queries that are written via the Log property of the DataContext but have so far been unable to identify a way of capturing the query results. My hope was to extend DataContext and override the 'ExecuteQuery' methods and capture the IQueryable there, afterwards calling ToList(), but unfortunately the methods are all non-virtual.

The motivation behind this is to capture the queries and results and store them in a serialized fashion for later replay.

Perhaps there is some monitor that I can use? I noticed the DbMonitor class but it wasn't obvious to me if this could be used.
charliemango
 
Posts: 2
Joined: Tue 29 Nov 2016 10:23

Re: Capture SQL execution results

Postby Shalex » Wed 30 Nov 2016 18:49

charliemango wrote:My hope was to extend DataContext and override the 'ExecuteQuery' methods and capture the IQueryable there, afterwards calling ToList(), but unfortunately the methods are all non-virtual.
We can set virtual modifier to the DataProvider.Execute overload with the Expression parameter:
Code: Select all
protected virtual IExecuteResult Execute(Expression query)

In this case you will be able to create an inheritor of DataProvider (OracleDataProvider, PgSqlDataProvider, etc) and override this method with your own code. Then use this DataProvider class with DataContext.

Does this approach suit your scenario? If so, please confirm your request.
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Re: Capture SQL execution results

Postby charliemango » Fri 09 Dec 2016 15:58

I have managed to find a roundabout solution involving wrapping Queryable and QueryProvider objects and capturing the DataContext.Log at query execution time. It's a bit messy, your solution sounds better.

I am using Devart.Data.Oracle.Linq, Version=4.2.292.0 and I don't see this Execute method defined in Devart.Data.Oracle.Linq.Provider.OracleDataProvider or Devart.Data.Linq.DataProvider. Can you direct me here? If all query execution gets passed through this method then it would be a much more convenient approach.

On a related note, is there a way to get access to the generated SQL at that point other than via the Log property? I ask because the SQL I catch via DataContext.Log is formatted with parameters as SQL comments and I don't see any way to override this formatting.
charliemango
 
Posts: 2
Joined: Tue 29 Nov 2016 10:23

Re: Capture SQL execution results

Postby Shalex » Tue 13 Dec 2016 14:23

charliemango wrote:I am using Devart.Data.Oracle.Linq, Version=4.2.292.0 and I don't see this Execute method defined in Devart.Data.Oracle.Linq.Provider.OracleDataProvider or Devart.Data.Linq.DataProvider. Can you direct me here? If all query execution gets passed through this method then it would be a much more convenient approach.
1. There is no such a method in a current implementation. Please confirm your request, and we will implement it.

charliemango wrote:On a related note, is there a way to get access to the generated SQL at that point other than via the Log property? I ask because the SQL I catch via DataContext.Log is formatted with parameters as SQL comments and I don't see any way to override this formatting.
2. The OracleDataProvider.LogCommand method is called before executing OracleCommand. Do you want to override it?
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle