# Global Event: OnExecuteSqlStatementConstructed

The OnExecuteSqlStatementConstructed Event occurs just before SQL is sent to the Data Source to retrieve data for report execution. This Event could be used to inspect, log or modify the SQL that is being used for report execution.

Signature

For custom code the args array is structured as follows:

args[] contains a string representing the execution SQL in position zero, and a SqlObject class wrapping the execution SQL string in position one.

For .Net Assemblies the method signature is as follows:

string EventHandlerName(SessionInfo sessionInfo, string executionSql, SqlObject sqlObject)

Expected Return

The OnExecuteSqlStatementConstructed Event expects either a SQL string return, to override the default execution SQL, or null, in which case the execution will continue as normal.

Example

The following example shows how report execution SQL can be written to a log file.

    // write the current time, companyId, userId and report name to a specified log file.
    File.WriteAllText("C:\ReportSqlLogFile", String.Format("{0}, {1}, {2}, {3}\n", DateTime.Now.ToString(), sessionInfo.CompanyId, sessionInfo.UserId, args[0]));
    // return null to proceed with execution
    return null;