mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 Aop.CommandBefore 设置 .CommandText = null 可拦截本次执行;
This commit is contained in:
parent
ef6d790dcc
commit
9118407952
@ -480,7 +480,11 @@ namespace base_entity
|
|||||||
|
|
||||||
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||||
|
|
||||||
.UseMonitorCommand(cmd => Console.WriteLine(cmd.CommandText + "\r\n"))
|
.UseMonitorCommand(cmd =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(cmd.CommandText + "\r\n");
|
||||||
|
cmd.CommandText = null; //不执行
|
||||||
|
})
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
//.UseGenerateCommandParameterWithLambda(true)
|
//.UseGenerateCommandParameterWithLambda(true)
|
||||||
.Build();
|
.Build();
|
||||||
|
@ -800,5 +800,14 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||||
|
<summary>
|
||||||
|
批量注入 Repository,可以参考代码自行调整
|
||||||
|
</summary>
|
||||||
|
<param name="services"></param>
|
||||||
|
<param name="globalDataFilter"></param>
|
||||||
|
<param name="assemblies"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -1413,6 +1413,15 @@
|
|||||||
<param name="convertType"></param>
|
<param name="convertType"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.FreeSqlBuilder.UseQuoteSqlName(System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
SQL名称是否使用 [] `` ""<para></para>
|
||||||
|
true: SELECT .. FROM [table]<para></para>
|
||||||
|
false: SELECT .. FROM table
|
||||||
|
</summary>
|
||||||
|
<param name="value"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.FreeSqlBuilder.UseMappingPriority(FreeSql.Internal.MappingPriorityType,FreeSql.Internal.MappingPriorityType,FreeSql.Internal.MappingPriorityType)">
|
<member name="M:FreeSql.FreeSqlBuilder.UseMappingPriority(FreeSql.Internal.MappingPriorityType,FreeSql.Internal.MappingPriorityType,FreeSql.Internal.MappingPriorityType)">
|
||||||
<summary>
|
<summary>
|
||||||
指定映射优先级<para></para>
|
指定映射优先级<para></para>
|
||||||
|
@ -159,6 +159,13 @@ namespace FreeSql
|
|||||||
_nameConvertType = convertType;
|
_nameConvertType = convertType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// SQL名称是否使用 [] `` ""<para></para>
|
||||||
|
/// true: SELECT .. FROM [table]<para></para>
|
||||||
|
/// false: SELECT .. FROM table
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public FreeSqlBuilder UseQuoteSqlName(bool value)
|
public FreeSqlBuilder UseQuoteSqlName(bool value)
|
||||||
{
|
{
|
||||||
_isQuoteSqlName = value;
|
_isQuoteSqlName = value;
|
||||||
|
@ -52,7 +52,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
TimeSpan ts = DateTime.Now.Subtract(dt);
|
TimeSpan ts = DateTime.Now.Subtract(dt);
|
||||||
if (ex == null && ts.TotalMilliseconds > 100)
|
if (ex == null && ts.TotalMilliseconds > 100)
|
||||||
Trace.WriteLine(logtxt.Insert(0, $"{pool?.Policy.Name}(执行SQL)语句耗时过长{ts.TotalMilliseconds}ms\r\n{cmd.CommandText}\r\n").ToString());
|
logtxt.Insert(0, $"{pool?.Policy.Name}(执行SQL)语句耗时过长{ts.TotalMilliseconds}ms\r\n{cmd.CommandText}\r\n").ToString();
|
||||||
else
|
else
|
||||||
logtxt.Insert(0, $"{pool?.Policy.Name}(执行SQL)耗时{ts.TotalMilliseconds}ms\r\n{cmd.CommandText}\r\n").ToString();
|
logtxt.Insert(0, $"{pool?.Policy.Name}(执行SQL)耗时{ts.TotalMilliseconds}ms\r\n{cmd.CommandText}\r\n").ToString();
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
log.Append(parm.ParameterName.PadRight(20, ' ')).Append(" = ").Append((parm.Value ?? DBNull.Value) == DBNull.Value ? "NULL" : parm.Value).Append("\r\n");
|
log.Append(parm.ParameterName.PadRight(20, ' ')).Append(" = ").Append((parm.Value ?? DBNull.Value) == DBNull.Value ? "NULL" : parm.Value).Append("\r\n");
|
||||||
|
|
||||||
log.Append(ex.Message);
|
log.Append(ex.Message);
|
||||||
Trace.WriteLine(log.ToString());
|
//Trace.WriteLine(log.ToString());
|
||||||
|
|
||||||
if (cmd.Transaction != null)
|
if (cmd.Transaction != null)
|
||||||
{
|
{
|
||||||
@ -601,6 +601,14 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
Object<DbConnection> conn = null;
|
Object<DbConnection> conn = null;
|
||||||
var pc = PrepareCommand(connection, transaction, cmdType, cmdText, cmdTimeout, cmdParms, logtxt);
|
var pc = PrepareCommand(connection, transaction, cmdType, cmdText, cmdTimeout, cmdParms, logtxt);
|
||||||
|
if (string.IsNullOrEmpty(pc.cmd.CommandText)) //被拦截 CommandBefore
|
||||||
|
{
|
||||||
|
LoggerException(pool, pc, null, dt, logtxt);
|
||||||
|
pc.cmd.Parameters.Clear();
|
||||||
|
if (DataType == DataType.Sqlite) pc.cmd.Dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsTracePerformance)
|
if (IsTracePerformance)
|
||||||
{
|
{
|
||||||
logtxt.Append("PrepareCommand: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n");
|
logtxt.Append("PrepareCommand: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n");
|
||||||
@ -785,8 +793,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
Exception ex = null;
|
Exception ex = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = this.MasterPool.Get()).Value;
|
if (string.IsNullOrEmpty(pc.cmd.CommandText) == false) //是否被拦截 CommandBefore
|
||||||
val = pc.cmd.ExecuteNonQuery();
|
{
|
||||||
|
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = this.MasterPool.Get()).Value;
|
||||||
|
val = pc.cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
@ -821,8 +832,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
Exception ex = null;
|
Exception ex = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = this.MasterPool.Get()).Value;
|
if (string.IsNullOrEmpty(pc.cmd.CommandText) == false) //是否被拦截 CommandBefore
|
||||||
val = pc.cmd.ExecuteScalar();
|
{
|
||||||
|
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = this.MasterPool.Get()).Value;
|
||||||
|
val = pc.cmd.ExecuteScalar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
|
@ -508,6 +508,14 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
Object<DbConnection> conn = null;
|
Object<DbConnection> conn = null;
|
||||||
var pc = await PrepareCommandAsync(connection, transaction, cmdType, cmdText, cmdTimeout, cmdParms, logtxt, cancellationToken);
|
var pc = await PrepareCommandAsync(connection, transaction, cmdType, cmdText, cmdTimeout, cmdParms, logtxt, cancellationToken);
|
||||||
|
if (string.IsNullOrEmpty(pc.cmd.CommandText)) //被拦截 CommandBefore
|
||||||
|
{
|
||||||
|
LoggerException(pool, pc, null, dt, logtxt);
|
||||||
|
pc.cmd.Parameters.Clear();
|
||||||
|
if (DataType == DataType.Sqlite) pc.cmd.Dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsTracePerformance)
|
if (IsTracePerformance)
|
||||||
{
|
{
|
||||||
logtxt.Append("PrepareCommand: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n");
|
logtxt.Append("PrepareCommand: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n");
|
||||||
@ -690,8 +698,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
Exception ex = null;
|
Exception ex = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = await this.MasterPool.GetAsync()).Value;
|
if (string.IsNullOrEmpty(pc.cmd.CommandText) == false) //是否被拦截 CommandBefore
|
||||||
val = await pc.cmd.ExecuteNonQueryAsync(cancellationToken);
|
{
|
||||||
|
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = await this.MasterPool.GetAsync()).Value;
|
||||||
|
val = await pc.cmd.ExecuteNonQueryAsync(cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
@ -726,8 +737,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
Exception ex = null;
|
Exception ex = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = await this.MasterPool.GetAsync()).Value;
|
if (string.IsNullOrEmpty(pc.cmd.CommandText) == false) //是否被拦截 CommandBefore
|
||||||
val = await pc.cmd.ExecuteScalarAsync(cancellationToken);
|
{
|
||||||
|
if (pc.cmd.Connection == null) pc.cmd.Connection = (conn = await this.MasterPool.GetAsync()).Value;
|
||||||
|
val = await pc.cmd.ExecuteScalarAsync(cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.WriteLine($"数据库出错(开启事务){ex.Message} \r\n{ex.StackTrace}");
|
//Trace.WriteLine($"数据库出错(开启事务){ex.Message} \r\n{ex.StackTrace}");
|
||||||
MasterPool.Return(conn);
|
MasterPool.Return(conn);
|
||||||
var after = new Aop.TraceAfterEventArgs(before, "", ex);
|
var after = new Aop.TraceAfterEventArgs(before, "", ex);
|
||||||
_util?._orm?.Aop.TraceAfterHandler?.Invoke(this, after);
|
_util?._orm?.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||||
@ -83,7 +83,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
if (tran.Transaction.Connection != null) //用户自行 Commit、Rollback
|
if (tran.Transaction.Connection != null) //用户自行 Commit、Rollback
|
||||||
{
|
{
|
||||||
Trace.WriteLine($"线程{tran.Connection.LastGetThreadId}事务{remark}");
|
//Trace.WriteLine($"线程{tran.Connection.LastGetThreadId}事务{remark}");
|
||||||
if (isCommit) tran.Transaction.Commit();
|
if (isCommit) tran.Transaction.Commit();
|
||||||
else tran.Transaction.Rollback();
|
else tran.Transaction.Rollback();
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
ex = ex2;
|
ex = ex2;
|
||||||
Trace.WriteLine($"数据库出错({remark}事务):{ex.Message} {ex.StackTrace}");
|
//Trace.WriteLine($"数据库出错({remark}事务):{ex.Message} {ex.StackTrace}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user