diff --git a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs index 5f7053b29..c8e6a3e05 100644 --- a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs @@ -601,6 +601,8 @@ namespace SqlSugar.TDSQLForPGODBC DataExecuted = it.AopEvents?.DataExecuted, CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, + OnGetDataReadered = it.AopEvents?.OnGetDataReadered, + OnGetDataReadering = it.AopEvents?.OnGetDataReadering, }, ConfigId = it.ConfigId, ConfigureExternalServices = it.ConfigureExternalServices == null ? null : new ConfigureExternalServices() diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 028ddf298..94058536b 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -40,6 +40,7 @@ namespace SqlSugar 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; /// @@ -48,6 +49,8 @@ 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 @@ -71,6 +74,8 @@ namespace SqlSugar 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; @@ -1048,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.ToString(); + 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(); @@ -1109,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); } } @@ -1173,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(); @@ -1230,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); } } @@ -1584,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.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs index 0055b586f..aee0d3e54 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs @@ -25,5 +25,7 @@ namespace SqlSugar public virtual Action DataExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuted = value; } } public Action CheckConnectionExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuting = value; } } public Action CheckConnectionExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuted = value; } } + public Action OnGetDataReadering { set { this.Context.CurrentConnectionConfig.AopEvents.OnGetDataReadering = value; } } + public Action OnGetDataReadered { set { this.Context.CurrentConnectionConfig.AopEvents.OnGetDataReadered = value; } } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 89fac2556..05dcdab7e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -1885,8 +1885,12 @@ namespace SqlSugar var entityType = typeof(TResult); bool isChangeQueryableSlave = GetIsSlaveQuery(); bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()); + string sqlString = sqlObj.Key; + SugarParameter[] parameters = sqlObj.Value.ToArray(); + var dataReader = this.Db.GetDataReader(sqlString, parameters); + this.Db.GetDataBefore(sqlString, parameters); result = GetData(isComplexModel, entityType, dataReader); + this.Db.GetDataAfter(sqlString, parameters); RestChangeMasterQuery(isChangeQueryableMasterSlave); RestChangeSlaveQuery(isChangeQueryableSlave); return result; @@ -1898,8 +1902,12 @@ namespace SqlSugar var entityType = typeof(TResult); bool isChangeQueryableSlave = GetIsSlaveQuery(); bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = await this.Db.GetDataReaderAsync(sqlObj.Key, sqlObj.Value.ToArray()); + string sqlString = sqlObj.Key; + SugarParameter[] parameters = sqlObj.Value.ToArray(); + var dataReader = await this.Db.GetDataReaderAsync(sqlString, parameters); + this.Db.GetDataBefore(sqlString, parameters); result = await GetDataAsync(isComplexModel, entityType, dataReader); + this.Db.GetDataAfter(sqlString, parameters); RestChangeMasterQuery(isChangeQueryableMasterSlave); RestChangeSlaveQuery(isChangeQueryableSlave); return result; diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs index a7082f67d..7c9babcc9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs @@ -96,6 +96,8 @@ namespace SqlSugar public Action DataExecuted { get; set; } public Action CheckConnectionExecuting { get; set; } public Action CheckConnectionExecuted { get; set; } + public Action OnGetDataReadering { get; set; } + public Action OnGetDataReadered { get; set; } } public class ConfigureExternalServices { diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs index 13e872cc3..549cc986a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs @@ -22,6 +22,8 @@ namespace SqlSugar void CheckConnectionBefore(IDbConnection Connection); void ExecuteBefore(string sql, SugarParameter[] pars); void ExecuteAfter(string sql, SugarParameter[] pars); + void GetDataBefore(string sql, SugarParameter[] parameters); + void GetDataAfter(string sql, SugarParameter[] parameters); bool IsAnyTran(); bool IsNoTran(); bool IsEnableLogEvent { get; set; } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index 0c70d49a3..134f11607 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -664,6 +664,8 @@ namespace SqlSugar DataExecuted = it.AopEvents?.DataExecuted, CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, + OnGetDataReadered= it.AopEvents?.OnGetDataReadered, + OnGetDataReadering = it.AopEvents?.OnGetDataReadering, }, ConfigId = it.ConfigId, ConfigureExternalServices =it.ConfigureExternalServices==null?null:new ConfigureExternalServices() {