From 1a63ccd707b0c1f9d00d82141a66d1b523e1e73b Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Mon, 16 Aug 2021 21:05:11 +0800 Subject: [PATCH] Update Core --- .../SqlSugar/Interface/ITenant.cs | 4 +- .../MySql/DbMaintenance/MySqlDbMaintenance.cs | 6 +-- .../Realization/MySql/MySqlProvider.cs | 1 - .../Realization/Oracle/DbBind/OracleDbBind.cs | 4 +- .../Realization/Oracle/OracleProvider.cs | 4 +- .../DbMaintenance/PostgreSQLDbMaintenance.cs | 4 +- .../SqlSeverTest/SqlSugar/SqlSugarClient.cs | 49 +++++++++++++++++-- .../SqlSeverTest/SqlSugar/SqlSugarScope.cs | 4 +- 8 files changed, 59 insertions(+), 17 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ITenant.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ITenant.cs index 23fc9ae6b..d94a8a2f1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ITenant.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ITenant.cs @@ -14,10 +14,10 @@ namespace SqlSugar void ChangeDatabase(dynamic configId); void ChangeDatabase(Func changeExpression); DbResult UseTran(Action action, Action errorCallBack = null); - Task> UseTranAsync(Action action, Action errorCallBack = null); + Task> UseTranAsync(Func action, Action errorCallBack = null); DbResult UseTran(Func action, Action errorCallBack = null); - Task> UseTranAsync(Func action, Action errorCallBack = null); + Task> UseTranAsync(Func> action, Action errorCallBack = null); void AddConnection(ConnectionConfig connection); SqlSugarProvider GetConnection(dynamic configId); bool IsAnyConnection(dynamic configId); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index 00b8d555c..d32d130d1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -35,7 +35,7 @@ namespace SqlSugar numeric_scale as Scale, numeric_scale as DecimalDigits FROM - Information_schema.columns where TABLE_NAME='{0}' and TABLE_SCHEMA=(select database()) ORDER BY TABLE_NAME"; + Information_schema.columns where TABLE_NAME='{0}' and TABLE_SCHEMA=(select database()) ORDER BY ordinal_position"; return sql; } } @@ -63,7 +63,7 @@ namespace SqlSugar { get { - return "CREATE DATABASE {0} CHARACTER SET utf8 COLLATE utf8_general_ci "; + return "CREATE DATABASE `{0}` CHARACTER SET utf8 COLLATE utf8_general_ci "; } } protected override string AddPrimaryKeySql @@ -252,7 +252,7 @@ namespace SqlSugar { get { - return "CREATE {3} INDEX Index_{0}_{2} ON {0} ({1})"; + return "CREATE {3} INDEX `Index_{0}_{2}` ON `{0}` ({1})"; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs index d3c3ffe74..d270f1c0f 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs index 42fb2ccbc..4bc548857 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -111,12 +111,12 @@ namespace SqlSugar new KeyValuePair("timestamp",CSharpDataType.DateTime), new KeyValuePair("timestamp with local time zone",CSharpDataType.DateTime), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), - new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), new KeyValuePair("float",CSharpDataType.@decimal), new KeyValuePair("blob",CSharpDataType.byteArray), new KeyValuePair("long raw",CSharpDataType.byteArray), + new KeyValuePair("longraw",CSharpDataType.byteArray), new KeyValuePair("raw",CSharpDataType.byteArray), new KeyValuePair("bfile",CSharpDataType.byteArray), new KeyValuePair("varbinary",CSharpDataType.byteArray) }; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs index 9f746c4e0..17d445c35 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs @@ -1,9 +1,8 @@ -using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Client; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -88,6 +87,7 @@ namespace SqlSugar sqlCommand.BindByName = true; sqlCommand.CommandType = this.CommandType; sqlCommand.CommandTimeout = this.CommandTimeOut; + sqlCommand.InitialLONGFetchSize = -1; if (this.Transaction != null) { sqlCommand.Transaction = (OracleTransaction)this.Transaction; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 5a9fa2516..ad9b46b47 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -21,8 +21,10 @@ namespace SqlSugar { string sql = @"select cast (pclass.oid as int4) as TableId,cast(ptables.tablename as varchar) as TableName, pcolumn.column_name as DbColumnName,pcolumn.udt_name as DataType, - pcolumn.character_maximum_length as Length, + CASE WHEN pcolumn.numeric_scale >0 THEN pcolumn.numeric_precision ELSE pcolumn.character_maximum_length END as Length, pcolumn.column_default as DefaultValue, + pcolumn.numeric_scale as DecimalDigits, + pcolumn.numeric_scale as Scale, col_description(pclass.oid, pcolumn.ordinal_position) as ColumnDescription, case when pkey.colname = pcolumn.column_name then true else false end as IsPrimaryKey, diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index fcc67e233..227c556ad 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -687,9 +687,29 @@ namespace SqlSugar return result; } - public Task> UseTranAsync(Action action, Action errorCallBack = null) + public async Task> UseTranAsync(Func action, Action errorCallBack = null) { - return Task.FromResult(UseTran(action, errorCallBack)); + var result = new DbResult(); + try + { + this.BeginTran(); + if (action != null) + await action(); + this.CommitTran(); + result.Data = result.IsSuccess = true; + } + catch (Exception ex) + { + result.ErrorException = ex; + result.ErrorMessage = ex.Message; + result.IsSuccess = false; + this.RollbackTran(); + if (errorCallBack != null) + { + errorCallBack(ex); + } + } + return result; } public DbResult UseTran(Func action, Action errorCallBack = null) @@ -717,9 +737,30 @@ namespace SqlSugar return result; } - public Task> UseTranAsync(Func action, Action errorCallBack = null) + public async Task> UseTranAsync(Func> action, Action errorCallBack = null) { - return Task.FromResult(UseTran(action, errorCallBack)); + var result = new DbResult(); + try + { + this.BeginTran(); + T data=default(T); + if (action != null) + data = await action(); + this.CommitTran(); + result.Data = data; + } + catch (Exception ex) + { + result.ErrorException = ex; + result.ErrorMessage = ex.Message; + result.IsSuccess = false; + this.RollbackTran(); + if (errorCallBack != null) + { + errorCallBack(ex); + } + } + return result; } public void RollbackTran() diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs index f77e8b29d..2bb7434ab 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs @@ -662,12 +662,12 @@ namespace SqlSugar return ScopedContext.UseTran(action,errorCallBack); } - public Task> UseTranAsync(Action action, Action errorCallBack = null) + public Task> UseTranAsync(Func action, Action errorCallBack = null) { return ScopedContext.UseTranAsync(action, errorCallBack); } - public Task> UseTranAsync(Func action, Action errorCallBack = null) + public Task> UseTranAsync(Func> action, Action errorCallBack = null) { return ScopedContext.UseTranAsync(action, errorCallBack); }