Support rewrite ado execution method

This commit is contained in:
sunkaixuan 2022-03-27 22:15:21 +08:00
parent 5a2e13c781
commit 3f56ba1240
2 changed files with 32 additions and 0 deletions

View File

@ -339,6 +339,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle==true)
return this.Context.CurrentConnectionConfig.SqlMiddle.ExecuteCommand(sql, parameters);
SetConnectionStart(sql);
if (this.ProcessingEventStartingSQL != null)
ExecuteProcessingSQL(ref sql,ref parameters);
@ -371,6 +373,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return this.Context.CurrentConnectionConfig.SqlMiddle.GetDataReader(sql, parameters);
SetConnectionStart(sql);
var isSp = this.CommandType == CommandType.StoredProcedure;
if (this.ProcessingEventStartingSQL != null)
@ -403,6 +407,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return this.Context.CurrentConnectionConfig.SqlMiddle.GetDataSetAll(sql, parameters);
SetConnectionStart(sql);
if (this.ProcessingEventStartingSQL != null)
ExecuteProcessingSQL(ref sql,ref parameters);
@ -438,6 +444,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return this.Context.CurrentConnectionConfig.SqlMiddle.GetScalar(sql, parameters);
SetConnectionStart(sql);
if (this.ProcessingEventStartingSQL != null)
ExecuteProcessingSQL(ref sql,ref parameters);
@ -473,6 +481,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return await this.Context.CurrentConnectionConfig.SqlMiddle.ExecuteCommandAsync(sql, parameters);
SetConnectionStart(sql);
if (this.ProcessingEventStartingSQL != null)
ExecuteProcessingSQL(ref sql,ref parameters);
@ -510,6 +520,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return await this.Context.CurrentConnectionConfig.SqlMiddle.GetDataReaderAsync(sql, parameters);
SetConnectionStart(sql);
var isSp = this.CommandType == CommandType.StoredProcedure;
if (this.ProcessingEventStartingSQL != null)
@ -547,6 +559,8 @@ namespace SqlSugar
InitParameters(ref sql, parameters);
if (FormatSql != null)
sql = FormatSql(sql);
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
return await this.Context.CurrentConnectionConfig.SqlMiddle.GetScalarAsync(sql, parameters);
SetConnectionStart(sql);
if (this.ProcessingEventStartingSQL != null)
ExecuteProcessingSQL(ref sql,ref parameters);

View File

@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
@ -61,6 +62,23 @@ namespace SqlSugar
[JsonIgnore]
public AopEvents AopEvents { get;set; }
/// <summary>
///
/// </summary>
public SqlMiddle SqlMiddle { get; set; }
}
public class SqlMiddle
{
public bool? IsSqlMiddle { get; set; }
public Func<string ,SugarParameter[],object> GetScalar { get; set; }
public Func<string, SugarParameter[],int> ExecuteCommand { get; set; }
public Func<string, SugarParameter[],IDataReader> GetDataReader { get; set; }
public Func<string, SugarParameter[],DataSet> GetDataSetAll { get; set; }
public Func<string, SugarParameter[], Task<object>> GetScalarAsync { get; set; }
public Func<string, SugarParameter[], Task<int>> ExecuteCommandAsync { get; set; }
public Func<string, SugarParameter[], Task<IDataReader>> GetDataReaderAsync { get; set; }
public Func<string, SugarParameter[], Task<DataSet>> GetDataSetAllAsync { get; set; }
}
public class AopEvents
{