@@ -257,12 +257,14 @@ internal static string LastSql(this IDbCommand dbCmd)
257
257
return dbCmd . CommandText ;
258
258
}
259
259
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 )
261
261
{
262
262
dbCmd . CommandText = sql ;
263
263
264
264
dbCmd . SetParameters ( sqlParams ) ;
265
265
266
+ commandFilter ? . Invoke ( dbCmd ) ;
267
+
266
268
if ( Log . IsDebugEnabled )
267
269
Log . DebugCommand ( dbCmd ) ;
268
270
@@ -274,13 +276,15 @@ internal static int ExecuteSql(this IDbCommand dbCmd, string sql, IEnumerable<ID
274
276
return dbCmd . ExecuteNonQuery ( ) ;
275
277
}
276
278
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 )
278
280
{
279
281
if ( anonType != null )
280
282
dbCmd . SetParameters ( anonType . ToObjectDictionary ( ) , excludeDefaults : false , sql : ref sql ) ;
281
283
282
284
dbCmd . CommandText = sql ;
283
285
286
+ commandFilter ? . Invoke ( dbCmd ) ;
287
+
284
288
if ( Log . IsDebugEnabled )
285
289
Log . DebugCommand ( dbCmd ) ;
286
290
@@ -510,12 +514,12 @@ private static int AssertRowsUpdated(IDbCommand dbCmd, bool hadRowVersion)
510
514
return rowsUpdated ;
511
515
}
512
516
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 )
514
518
{
515
- return dbCmd . Delete < T > ( ( object ) anonType ) ;
519
+ return dbCmd . Delete < T > ( ( object ) anonType , commandFilter ) ;
516
520
}
517
521
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 )
519
523
{
520
524
var dialectProvider = dbCmd . GetDialectProvider ( ) ;
521
525
@@ -524,6 +528,8 @@ internal static int Delete<T>(this IDbCommand dbCmd, object anonType)
524
528
525
529
dialectProvider . SetParameterValues < T > ( dbCmd , anonType ) ;
526
530
531
+ commandFilter ? . Invoke ( dbCmd ) ;
532
+
527
533
return AssertRowsUpdated ( dbCmd , hadRowVersion ) ;
528
534
}
529
535
@@ -553,7 +559,7 @@ internal static int DeleteNonDefaults<T>(this IDbCommand dbCmd, T[] filters)
553
559
return DeleteAll ( dbCmd , filters , o => o . AllFieldsMap < T > ( ) . NonDefaultsOnly ( ) ) ;
554
560
}
555
561
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 )
557
563
{
558
564
OrmLiteUtils . AssertNotAnonType < T > ( ) ;
559
565
@@ -577,6 +583,9 @@ private static int DeleteAll<T>(IDbCommand dbCmd, IEnumerable<T> objs, Func<obje
577
583
578
584
dialectProvider . SetParameterValues < T > ( dbCmd , obj ) ;
579
585
586
+ commandFilter ? . Invoke ( dbCmd ) ;
587
+ commandFilter = null ;
588
+
580
589
count += dbCmd . ExecNonQuery ( ) ;
581
590
}
582
591
@@ -590,11 +599,11 @@ private static int DeleteAll<T>(IDbCommand dbCmd, IEnumerable<T> objs, Func<obje
590
599
return count ;
591
600
}
592
601
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 )
594
603
{
595
604
var sql = DeleteByIdSql < T > ( dbCmd , id ) ;
596
605
597
- return dbCmd . ExecuteSql ( sql ) ;
606
+ return dbCmd . ExecuteSql ( sql , commandFilter : commandFilter ) ;
598
607
}
599
608
600
609
internal static string DeleteByIdSql < T > ( this IDbCommand dbCmd , object id )
@@ -613,11 +622,11 @@ internal static string DeleteByIdSql<T>(this IDbCommand dbCmd, object id)
613
622
return sql ;
614
623
}
615
624
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 )
617
626
{
618
627
var sql = DeleteByIdSql < T > ( dbCmd , id , rowVersion ) ;
619
628
620
- var rowsAffected = dbCmd . ExecuteSql ( sql ) ;
629
+ var rowsAffected = dbCmd . ExecuteSql ( sql , commandFilter : commandFilter ) ;
621
630
if ( rowsAffected == 0 )
622
631
throw new OptimisticConcurrencyException ( "The row was modified or deleted since the last read" ) ;
623
632
}
0 commit comments