@@ -257,12 +257,14 @@ internal static string LastSql(this IDbCommand dbCmd)
257257 return dbCmd . CommandText ;
258258 }
259259
260- internal static int ExecuteSql ( this IDbCommand dbCmd , string sql , IEnumerable < IDbDataParameter > sqlParams = null )
260+ internal static int ExecuteSql ( this IDbCommand dbCmd , string sql , IEnumerable < IDbDataParameter > sqlParams = null , Action < IDbCommand > commandFilter = null )
261261 {
262262 dbCmd . CommandText = sql ;
263263
264264 dbCmd . SetParameters ( sqlParams ) ;
265265
266+ commandFilter ? . Invoke ( dbCmd ) ;
267+
266268 if ( Log . IsDebugEnabled )
267269 Log . DebugCommand ( dbCmd ) ;
268270
@@ -274,13 +276,15 @@ internal static int ExecuteSql(this IDbCommand dbCmd, string sql, IEnumerable<ID
274276 return dbCmd . ExecuteNonQuery ( ) ;
275277 }
276278
277- internal static int ExecuteSql ( this IDbCommand dbCmd , string sql , object anonType )
279+ internal static int ExecuteSql ( this IDbCommand dbCmd , string sql , object anonType , Action < IDbCommand > commandFilter = null )
278280 {
279281 if ( anonType != null )
280282 dbCmd . SetParameters ( anonType . ToObjectDictionary ( ) , excludeDefaults : false , sql : ref sql ) ;
281283
282284 dbCmd . CommandText = sql ;
283285
286+ commandFilter ? . Invoke ( dbCmd ) ;
287+
284288 if ( Log . IsDebugEnabled )
285289 Log . DebugCommand ( dbCmd ) ;
286290
@@ -510,12 +514,12 @@ private static int AssertRowsUpdated(IDbCommand dbCmd, bool hadRowVersion)
510514 return rowsUpdated ;
511515 }
512516
513- internal static int Delete < T > ( this IDbCommand dbCmd , T anonType )
517+ internal static int Delete < T > ( this IDbCommand dbCmd , T anonType , Action < IDbCommand > commandFilter = null )
514518 {
515- return dbCmd . Delete < T > ( ( object ) anonType ) ;
519+ return dbCmd . Delete < T > ( ( object ) anonType , commandFilter ) ;
516520 }
517521
518- internal static int Delete < T > ( this IDbCommand dbCmd , object anonType )
522+ internal static int Delete < T > ( this IDbCommand dbCmd , object anonType , Action < IDbCommand > commandFilter = null )
519523 {
520524 var dialectProvider = dbCmd . GetDialectProvider ( ) ;
521525
@@ -524,6 +528,8 @@ internal static int Delete<T>(this IDbCommand dbCmd, object anonType)
524528
525529 dialectProvider . SetParameterValues < T > ( dbCmd , anonType ) ;
526530
531+ commandFilter ? . Invoke ( dbCmd ) ;
532+
527533 return AssertRowsUpdated ( dbCmd , hadRowVersion ) ;
528534 }
529535
@@ -553,7 +559,7 @@ internal static int DeleteNonDefaults<T>(this IDbCommand dbCmd, T[] filters)
553559 return DeleteAll ( dbCmd , filters , o => o . AllFieldsMap < T > ( ) . NonDefaultsOnly ( ) ) ;
554560 }
555561
556- private static int DeleteAll < T > ( IDbCommand dbCmd , IEnumerable < T > objs , Func < object , Dictionary < string , object > > fieldValuesFn = null )
562+ private static int DeleteAll < T > ( IDbCommand dbCmd , IEnumerable < T > objs , Func < object , Dictionary < string , object > > fieldValuesFn = null , Action < IDbCommand > commandFilter = null )
557563 {
558564 OrmLiteUtils . AssertNotAnonType < T > ( ) ;
559565
@@ -577,6 +583,9 @@ private static int DeleteAll<T>(IDbCommand dbCmd, IEnumerable<T> objs, Func<obje
577583
578584 dialectProvider . SetParameterValues < T > ( dbCmd , obj ) ;
579585
586+ commandFilter ? . Invoke ( dbCmd ) ;
587+ commandFilter = null ;
588+
580589 count += dbCmd . ExecNonQuery ( ) ;
581590 }
582591
@@ -590,11 +599,11 @@ private static int DeleteAll<T>(IDbCommand dbCmd, IEnumerable<T> objs, Func<obje
590599 return count ;
591600 }
592601
593- internal static int DeleteById < T > ( this IDbCommand dbCmd , object id )
602+ internal static int DeleteById < T > ( this IDbCommand dbCmd , object id , Action < IDbCommand > commandFilter = null )
594603 {
595604 var sql = DeleteByIdSql < T > ( dbCmd , id ) ;
596605
597- return dbCmd . ExecuteSql ( sql ) ;
606+ return dbCmd . ExecuteSql ( sql , commandFilter : commandFilter ) ;
598607 }
599608
600609 internal static string DeleteByIdSql < T > ( this IDbCommand dbCmd , object id )
@@ -613,11 +622,11 @@ internal static string DeleteByIdSql<T>(this IDbCommand dbCmd, object id)
613622 return sql ;
614623 }
615624
616- internal static void DeleteById < T > ( this IDbCommand dbCmd , object id , ulong rowVersion )
625+ internal static void DeleteById < T > ( this IDbCommand dbCmd , object id , ulong rowVersion , Action < IDbCommand > commandFilter = null )
617626 {
618627 var sql = DeleteByIdSql < T > ( dbCmd , id , rowVersion ) ;
619628
620- var rowsAffected = dbCmd . ExecuteSql ( sql ) ;
629+ var rowsAffected = dbCmd . ExecuteSql ( sql , commandFilter : commandFilter ) ;
621630 if ( rowsAffected == 0 )
622631 throw new OptimisticConcurrencyException ( "The row was modified or deleted since the last read" ) ;
623632 }
0 commit comments