From 3f56ba12405c271acb26aac26d0702bd5f68a82c Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Sun, 27 Mar 2022 22:15:21 +0800
Subject: [PATCH] Support rewrite ado execution method
---
.../Abstract/AdoProvider/AdoProvider.cs | 14 ++++++++++++++
.../SqlSugar/Entities/ConnectionConfig.cs | 18 ++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
index 2087ec38a..b3c791444 100644
--- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
+++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
@@ -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);
diff --git a/Src/Asp.Net/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.Net/SqlSugar/Entities/ConnectionConfig.cs
index a6d088004..7b02f15a2 100644
--- a/Src/Asp.Net/SqlSugar/Entities/ConnectionConfig.cs
+++ b/Src/Asp.Net/SqlSugar/Entities/ConnectionConfig.cs
@@ -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; }
+ ///
+ ///
+ ///
+ public SqlMiddle SqlMiddle { get; set; }
+ }
+ public class SqlMiddle
+ {
+ public bool? IsSqlMiddle { get; set; }
+ public Func GetScalar { get; set; }
+ public Func ExecuteCommand { get; set; }
+ public Func GetDataReader { get; set; }
+ public Func GetDataSetAll { get; set; }
+ public Func> GetScalarAsync { get; set; }
+ public Func> ExecuteCommandAsync { get; set; }
+ public Func> GetDataReaderAsync { get; set; }
+ public Func> GetDataSetAllAsync { get; set; }
+
}
public class AopEvents
{