public static String adHocSQLFromInvocationForDebug ( StoredProcedureInvocation invocation ) { assert ( invocation . getProcName ( ) . startsWith ( "@AdHoc" ) ) ; ParameterSet params = invocation . getParams ( ) ; // the final param is the byte array we need byte [ ] serializedBatchData = ( byte [ ] ) params . getParam ( params . size ( ) - 1 ) ; Pair < Object [ ] , AdHocPlannedStatement [ ] > data = decodeSerializedBatchData ( serializedBatchData ) ; Object [ ] userparams = data . getFirst ( ) ; AdHocPlannedStatement [ ] statements = data . getSecond ( ) ; StringBuilder sb = new StringBuilder ( ) ; if ( statements . length == 0 ) { sb . append ( "ADHOC INVOCATION HAS NO SQL" ) ; } else if ( statements . length == 1 ) { sb . append ( adHocSQLStringFromPlannedStatement ( statements [ 0 ] , userparams ) ) ; } else { // > 1 sb . append ( "BEGIN ADHOC_SQL_BATCH {\n" ) ; for ( AdHocPlannedStatement stmt : statements ) { sb . append ( adHocSQLStringFromPlannedStatement ( stmt , userparams ) ) . append ( "\n" ) ; } sb . append ( "} END ADHOC_SQL_BATCH" ) ; } return sb . toString ( ) ; }
Get a string containing the SQL statements and any parameters for a given batch passed to an ad - hoc query . Used for debugging and logging .