From 392dce7af6ffce2755a0dff64b288c038ec3141c Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Sun, 12 Jan 2025 15:21:43 +0800
Subject: [PATCH] Synchronization code
---
.../Abstract/AdoProvider/AdoProvider.cs | 88 ++++++++++++++++++-
.../Abstract/AopProvider/AopProvider.cs | 5 ++
.../DbBindProvider/DbBindAccessory.cs | 1 +
.../Abstract/FastestProvider/SplitFastest.cs | 8 ++
.../InsertableProvider/InsertablePage.cs | 4 +-
.../InsertableProvider/InsertableProvider.cs | 16 +++-
.../QueryableProvider/QueryMethodInfo.cs | 13 ++-
.../QueryableProvider/QueryableExecuteSql.cs | 6 +-
.../QueryableProvider/QueryableHelper.cs | 12 ++-
.../SqlBuilderProvider/QueryBuilder.cs | 20 ++++-
.../SqlBuilderProvider/UpdateBuilder.cs | 5 ++
.../SqlSugar/Entities/ConnectionConfig.cs | 4 +
.../SqlSugar/Infrastructure/StaticConfig.cs | 1 +
Src/Asp.Net/SqlSugar/Interface/IAdo.cs | 29 +++---
Src/Asp.Net/SqlSugar/Interface/Insertable.cs | 1 +
.../SqlSugar/Utilities/UtilConstants.cs | 3 +-
Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs | 4 +
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 6 +-
18 files changed, 201 insertions(+), 25 deletions(-)
diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
index b452294e4..196da4339 100644
--- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
+++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
@@ -39,6 +39,8 @@ namespace SqlSugar
internal bool OldClearParameters { get; set; }
public IDataParameterCollection DataReaderParameters { get; set; }
public TimeSpan SqlExecutionTime { get { return AfterTime - BeforeTime; } }
+ public TimeSpan ConnectionExecutionTime { get { return CheckConnectionAfterTime - CheckConnectionBeforeTime; } }
+ public TimeSpan GetDataExecutionTime { get { return GetDataAfterTime - GetDataBeforeTime; } }
///
/// Add, delete and modify: the number of affected items;
///
@@ -47,6 +49,10 @@ namespace SqlSugar
public bool IsDisableMasterSlaveSeparation { get; set; }
internal DateTime BeforeTime = DateTime.MinValue;
internal DateTime AfterTime = DateTime.MinValue;
+ internal DateTime GetDataBeforeTime = DateTime.MinValue;
+ internal DateTime GetDataAfterTime = DateTime.MinValue;
+ internal DateTime CheckConnectionBeforeTime = DateTime.MinValue;
+ internal DateTime CheckConnectionAfterTime = DateTime.MinValue;
public virtual IDbBind DbBind
{
get
@@ -66,6 +72,10 @@ namespace SqlSugar
public virtual bool IsClearParameters { get; set; }
public virtual Action LogEventStarting => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuting;
public virtual Action LogEventCompleted => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuted;
+ public virtual Action CheckConnectionExecuting => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuting;
+ public virtual Action CheckConnectionExecuted => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuted;
+ public virtual Action OnGetDataReadering => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadering;
+ public virtual Action OnGetDataReadered => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadered;
public virtual Func> ProcessingEventStartingSQL => this.Context.CurrentConnectionConfig.AopEvents?.OnExecutingChangeSql;
protected virtual Func FormatSql { get; set; }
public virtual Action ErrorEvent => this.Context.CurrentConnectionConfig.AopEvents?.OnError;
@@ -175,6 +185,7 @@ namespace SqlSugar
}
public virtual void CheckConnection()
{
+ this.CheckConnectionBefore(this.Connection);
if (this.Connection.State != ConnectionState.Open)
{
try
@@ -190,10 +201,12 @@ namespace SqlSugar
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message+$"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\"");
}
}
+ this.CheckConnectionAfter(this.Connection);
}
public virtual async Task CheckConnectionAsync()
{
+ this.CheckConnectionBefore(this.Connection);
if (this.Connection.State != ConnectionState.Open)
{
try
@@ -205,6 +218,31 @@ namespace SqlSugar
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message + $"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\"");
}
}
+ this.CheckConnectionAfter(this.Connection);
+ }
+ public virtual void CheckConnectionBefore(IDbConnection Connection)
+ {
+ this.CheckConnectionBeforeTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = CheckConnectionExecuting;
+ if (action != null)
+ {
+ action(Connection);
+ }
+ }
+ }
+ public virtual void CheckConnectionAfter(IDbConnection Connection)
+ {
+ this.CheckConnectionAfterTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = CheckConnectionExecuted;
+ if (action != null)
+ {
+ action(Connection,this.ConnectionExecutionTime);
+ }
+ }
}
#endregion
@@ -1015,7 +1053,10 @@ namespace SqlSugar
builder.SqlQueryBuilder.sql.Append(sql);
if (parsmeterArray != null && parsmeterArray.Any())
builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray);
- using (var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
+ string sqlString = builder.SqlQueryBuilder.ToSqlString();
+ SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray();
+ this.GetDataBefore(sqlString, Parameters);
+ using (var dataReader = this.GetDataReader(sqlString, Parameters))
{
DbDataReader DbReader = (DbDataReader)dataReader;
List result = new List();
@@ -1076,6 +1117,7 @@ namespace SqlSugar
}
this.Context.Ado.DataReaderParameters = null;
}
+ this.GetDataAfter(sqlString, Parameters);
return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7);
}
}
@@ -1140,7 +1182,10 @@ namespace SqlSugar
builder.SqlQueryBuilder.sql.Append(sql);
if (parsmeterArray != null && parsmeterArray.Any())
builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray);
- using (var dataReader = await this.GetDataReaderAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
+ string sqlString = builder.SqlQueryBuilder.ToSqlString();
+ SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray();
+ this.GetDataBefore(sqlString, Parameters);
+ using (var dataReader = await this.GetDataReaderAsync(sqlString, Parameters))
{
DbDataReader DbReader = (DbDataReader)dataReader;
List result = new List();
@@ -1197,6 +1242,7 @@ namespace SqlSugar
}
this.Context.Ado.DataReaderParameters = null;
}
+ this.GetDataAfter(sqlString, Parameters);
return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7);
}
}
@@ -1551,6 +1597,44 @@ namespace SqlSugar
this.OldClearParameters = false;
}
}
+ public virtual void GetDataBefore(string sql, SugarParameter[] parameters)
+ {
+ this.GetDataBeforeTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = OnGetDataReadering;
+ if (action != null)
+ {
+ if (parameters == null || parameters.Length == 0)
+ {
+ action(sql, new SugarParameter[] { });
+ }
+ else
+ {
+ action(sql, parameters);
+ }
+ }
+ }
+ }
+ public virtual void GetDataAfter(string sql, SugarParameter[] parameters)
+ {
+ this.GetDataAfterTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = OnGetDataReadered;
+ if (action != null)
+ {
+ if (parameters == null || parameters.Length == 0)
+ {
+ action(sql, new SugarParameter[] { }, GetDataExecutionTime);
+ }
+ else
+ {
+ action(sql, parameters, GetDataExecutionTime);
+ }
+ }
+ }
+ }
public virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo = null)
{
if (parameters == null) return null;
diff --git a/Src/Asp.Net/SqlSugar/Abstract/AopProvider/AopProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AopProvider/AopProvider.cs
index 01949351d..aee0d3e54 100644
--- a/Src/Asp.Net/SqlSugar/Abstract/AopProvider/AopProvider.cs
+++ b/Src/Asp.Net/SqlSugar/Abstract/AopProvider/AopProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
@@ -22,5 +23,9 @@ namespace SqlSugar
public virtual Action