mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Update .net core project
This commit is contained in:
@@ -502,6 +502,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (properyTypeName?.ToLower() == "int" && dataType?.ToLower() == "int32")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (properyTypeName?.ToLower() == "date" && dataType?.ToLower() == "datetime")
|
if (properyTypeName?.ToLower() == "date" && dataType?.ToLower() == "datetime")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@@ -30,7 +30,7 @@ namespace SqlSugar
|
|||||||
resultConnector.CharacterSet = this.CharacterSet;
|
resultConnector.CharacterSet = this.CharacterSet;
|
||||||
return resultConnector;
|
return resultConnector;
|
||||||
case DbType.Dm:
|
case DbType.Dm:
|
||||||
break;
|
return new DmFastBuilder();
|
||||||
case DbType.Kdbndp:
|
case DbType.Kdbndp:
|
||||||
break;
|
break;
|
||||||
case DbType.Oscar:
|
case DbType.Oscar:
|
||||||
|
@@ -8,6 +8,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubOrderBy : ISubOperation
|
public class SubOrderBy : ISubOperation
|
||||||
{
|
{
|
||||||
|
public int OrderIndex { get; set; } = 0;
|
||||||
public bool HasWhere
|
public bool HasWhere
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -27,7 +28,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return 480;
|
return 480+OrderIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var argExp = exp.Arguments[0];
|
var argExp = exp.Arguments[0];
|
||||||
var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
|
var result =(OrderIndex==0? "ORDER BY ":",") + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
|
||||||
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||||
return result;
|
return result;
|
||||||
@@ -52,6 +53,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public class SubOrderByDesc : ISubOperation
|
public class SubOrderByDesc : ISubOperation
|
||||||
{
|
{
|
||||||
|
public int OrderIndex { get; set; } = 0;
|
||||||
public bool HasWhere
|
public bool HasWhere
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -71,7 +73,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return 480;
|
return 480+OrderIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var argExp = exp.Arguments[0];
|
var argExp = exp.Arguments[0];
|
||||||
var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
|
var result = (OrderIndex == 0 ? "ORDER BY " : ",") + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
|
||||||
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
result = result.Replace(selfParameterName, string.Empty);
|
result = result.Replace(selfParameterName, string.Empty);
|
||||||
return result;
|
return result;
|
||||||
|
@@ -168,41 +168,42 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var isSubSubQuery = this.allMethods.Select(it => it.ToString()).Any(it => Regex.Matches(it, "Subquery").Count > 1);
|
var isSubSubQuery = this.allMethods.Select(it => it.ToString()).Any(it => Regex.Matches(it, "Subquery").Count > 1);
|
||||||
var isubList = this.allMethods.Select(exp =>
|
var isubList = this.allMethods.Select(exp =>
|
||||||
{
|
{
|
||||||
if (isSubSubQuery)
|
if (isSubSubQuery)
|
||||||
{
|
{
|
||||||
this.context.JoinIndex = 1;
|
this.context.JoinIndex = 1;
|
||||||
this.context.SubQueryIndex = 0;
|
this.context.SubQueryIndex = 0;
|
||||||
}
|
}
|
||||||
var methodName = exp.Method.Name;
|
var methodName = exp.Method.Name;
|
||||||
var items = SubTools.SubItems(this.context);
|
var items = SubTools.SubItems(this.context);
|
||||||
var item = items.First(s => s.Name == methodName);
|
var item = items.First(s => s.Name == methodName);
|
||||||
if (item is SubWhere && hasWhere == false)
|
if (item is SubWhere && hasWhere == false)
|
||||||
{
|
{
|
||||||
hasWhere = true;
|
hasWhere = true;
|
||||||
}
|
}
|
||||||
else if (item is SubWhere)
|
else if (item is SubWhere)
|
||||||
{
|
{
|
||||||
item = items.First(s => s is SubAnd);
|
item = items.First(s => s is SubAnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item is SubWhereIF && hasWhere == false)
|
if (item is SubWhereIF && hasWhere == false)
|
||||||
{
|
{
|
||||||
hasWhere = true;
|
hasWhere = true;
|
||||||
}
|
}
|
||||||
else if (item is SubWhereIF)
|
else if (item is SubWhereIF)
|
||||||
{
|
{
|
||||||
item = items.First(s => s is SubAndIF);
|
item = items.First(s => s is SubAndIF);
|
||||||
}
|
}
|
||||||
else if (item is SubSelectStringJoin)
|
else if (item is SubSelectStringJoin)
|
||||||
{
|
{
|
||||||
isXmlPath = true;
|
isXmlPath = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Context = this.context;
|
item.Context = this.context;
|
||||||
item.Expression = exp;
|
item.Expression = exp;
|
||||||
return item;
|
return item;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
SetOrderByIndex(isubList);
|
||||||
isubList.Insert(0, new SubBegin());
|
isubList.Insert(0, new SubBegin());
|
||||||
if (isubList.Any(it => it is SubSelect))
|
if (isubList.Any(it => it is SubSelect))
|
||||||
{
|
{
|
||||||
@@ -229,5 +230,28 @@ namespace SqlSugar
|
|||||||
this.context.JoinIndex = 0;
|
this.context.JoinIndex = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetOrderByIndex(List<ISubOperation> isubList)
|
||||||
|
{
|
||||||
|
var orderByIndex = 0;
|
||||||
|
var orderByList = isubList.Where(it => it is SubOrderBy || it is SubOrderByDesc).ToList();
|
||||||
|
if (orderByList.Count > 1)
|
||||||
|
{
|
||||||
|
orderByList.Reverse();
|
||||||
|
foreach (var item in orderByList)
|
||||||
|
{
|
||||||
|
if (item is SubOrderBy)
|
||||||
|
{
|
||||||
|
(item as SubOrderBy).OrderIndex = orderByIndex;
|
||||||
|
orderByIndex++;
|
||||||
|
}
|
||||||
|
else if (item is SubOrderByDesc)
|
||||||
|
{
|
||||||
|
(item as SubOrderByDesc).OrderIndex = orderByIndex;
|
||||||
|
orderByIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,23 +16,28 @@ namespace SqlSugar
|
|||||||
public DmProvider() {
|
public DmProvider() {
|
||||||
this.FormatSql = sql =>
|
this.FormatSql = sql =>
|
||||||
{
|
{
|
||||||
var guid = Guid.NewGuid();
|
|
||||||
sql = sql.Replace("+@", "+:");
|
sql = sql.Replace("+@", "+:");
|
||||||
sql = sql.Replace("select @@identity", guid.ToString());
|
|
||||||
if (sql.HasValue() && sql.Contains("@"))
|
if (sql.HasValue() && sql.Contains("@"))
|
||||||
{
|
{
|
||||||
var exceptionalCaseInfo = Regex.Matches(sql, @"\'.*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+");
|
var exceptionalCaseInfo = Regex.Matches(sql, @"\'[^\=]*?\@.*?\'|[\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+|[\.,\w]+\@[\.,\w]+ |\d+\@\d|\@\@");
|
||||||
if (exceptionalCaseInfo != null)
|
if (exceptionalCaseInfo != null)
|
||||||
{
|
{
|
||||||
foreach (var item in exceptionalCaseInfo.Cast<Match>())
|
foreach (var item in exceptionalCaseInfo.Cast<Match>())
|
||||||
{
|
{
|
||||||
|
if (item.Value != null && item.Value.IndexOf(",") == 1 && Regex.IsMatch(item.Value, @"^ \,\@\w+$"))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (item.Value != null && Regex.IsMatch(item.Value.Trim(), @"^\w+\,\@\w+\,$"))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
sql = sql.Replace(item.Value, item.Value.Replace("@", UtilConstants.ReplaceKey));
|
sql = sql.Replace(item.Value, item.Value.Replace("@", UtilConstants.ReplaceKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sql = sql.Replace("@", ":");
|
sql = sql.Replace("@", ":");
|
||||||
sql = sql.Replace(UtilConstants.ReplaceKey, "@");
|
sql = sql.Replace(UtilConstants.ReplaceKey, "@");
|
||||||
}
|
}
|
||||||
sql = sql.Replace(guid.ToString(), "select @@identity");
|
|
||||||
return sql;
|
return sql;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -118,6 +123,10 @@ namespace SqlSugar
|
|||||||
sqlParameter.Size = parameter.Size;
|
sqlParameter.Size = parameter.Size;
|
||||||
sqlParameter.Value = parameter.Value;
|
sqlParameter.Value = parameter.Value;
|
||||||
sqlParameter.DbType = parameter.DbType;
|
sqlParameter.DbType = parameter.DbType;
|
||||||
|
if (sqlParameter.ParameterName[0] == '@')
|
||||||
|
{
|
||||||
|
sqlParameter.ParameterName = ':' + sqlParameter.ParameterName.Substring(1, sqlParameter.ParameterName.Length - 1);
|
||||||
|
}
|
||||||
if (sqlParameter.DbType == System.Data.DbType.Guid)
|
if (sqlParameter.DbType == System.Data.DbType.Guid)
|
||||||
{
|
{
|
||||||
sqlParameter.DbType = System.Data.DbType.String;
|
sqlParameter.DbType = System.Data.DbType.String;
|
||||||
|
@@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class DmBlukCopy
|
||||||
|
{
|
||||||
|
internal List<IGrouping<int, DbColumnInfo>> DbColumnInfoList { get; set; }
|
||||||
|
internal SqlSugarProvider Context { get; set; }
|
||||||
|
internal ISqlBuilder Builder { get; set; }
|
||||||
|
internal InsertBuilder InsertBuilder { get; set; }
|
||||||
|
internal object[] Inserts { get; set; }
|
||||||
|
|
||||||
|
public int ExecuteBulkCopy()
|
||||||
|
{
|
||||||
|
if (DbColumnInfoList == null || DbColumnInfoList.Count == 0) return 0;
|
||||||
|
|
||||||
|
if (Inserts.First().GetType() == typeof(DataTable))
|
||||||
|
{
|
||||||
|
return WriteToServer();
|
||||||
|
}
|
||||||
|
DataTable dt = GetCopyData();
|
||||||
|
SqlBulkCopy bulkCopy = GetBulkCopyInstance();
|
||||||
|
bulkCopy.DestinationTableName = InsertBuilder.GetTableNameString;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bulkCopy.WriteToServer(dt);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CloseDb();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
CloseDb();
|
||||||
|
return DbColumnInfoList.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> ExecuteBulkCopyAsync()
|
||||||
|
{
|
||||||
|
if (DbColumnInfoList == null || DbColumnInfoList.Count == 0) return 0;
|
||||||
|
|
||||||
|
if (Inserts.First().GetType() == typeof(DataTable))
|
||||||
|
{
|
||||||
|
return WriteToServer();
|
||||||
|
}
|
||||||
|
DataTable dt=GetCopyData();
|
||||||
|
SqlBulkCopy bulkCopy = GetBulkCopyInstance();
|
||||||
|
bulkCopy.DestinationTableName = InsertBuilder.GetTableNameString;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await bulkCopy.WriteToServerAsync(dt);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CloseDb();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
CloseDb();
|
||||||
|
return DbColumnInfoList.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int WriteToServer()
|
||||||
|
{
|
||||||
|
var dt = this.Inserts.First() as DataTable;
|
||||||
|
if (dt == null)
|
||||||
|
return 0;
|
||||||
|
Check.Exception(dt.TableName == "Table", "dt.TableName can't be null ");
|
||||||
|
dt = GetCopyWriteDataTable(dt);
|
||||||
|
SqlBulkCopy copy = GetBulkCopyInstance();
|
||||||
|
copy.DestinationTableName = this.Builder.GetTranslationColumnName(dt.TableName);
|
||||||
|
copy.WriteToServer(dt);
|
||||||
|
CloseDb();
|
||||||
|
return dt.Rows.Count;
|
||||||
|
}
|
||||||
|
private DataTable GetCopyWriteDataTable(DataTable dt)
|
||||||
|
{
|
||||||
|
var result = this.Context.Ado.GetDataTable("select top 0 * from " + this.Builder.GetTranslationColumnName(dt.TableName));
|
||||||
|
foreach (DataRow item in dt.Rows)
|
||||||
|
{
|
||||||
|
DataRow dr= result.NewRow();
|
||||||
|
foreach (DataColumn column in result.Columns)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (dt.Columns.Cast<DataColumn>().Select(it => it.ColumnName.ToLower()).Contains(column.ColumnName.ToLower()))
|
||||||
|
{
|
||||||
|
dr[column.ColumnName] = item[column.ColumnName];
|
||||||
|
if (dr[column.ColumnName] == null)
|
||||||
|
{
|
||||||
|
dr[column.ColumnName] = DBNull.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.Rows.Add(dr);
|
||||||
|
}
|
||||||
|
result.TableName = dt.TableName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private SqlBulkCopy GetBulkCopyInstance()
|
||||||
|
{
|
||||||
|
SqlBulkCopy copy;
|
||||||
|
if (this.Context.Ado.Transaction == null)
|
||||||
|
{
|
||||||
|
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction);
|
||||||
|
}
|
||||||
|
if (this.Context.Ado.Connection.State == ConnectionState.Closed)
|
||||||
|
{
|
||||||
|
this.Context.Ado.Connection.Open();
|
||||||
|
}
|
||||||
|
copy.BulkCopyTimeout = this.Context.Ado.CommandTimeOut;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
private DataTable GetCopyData()
|
||||||
|
{
|
||||||
|
var dt = this.Context.Ado.GetDataTable("select top 0 * from " + InsertBuilder.GetTableNameString);
|
||||||
|
foreach (var rowInfos in DbColumnInfoList)
|
||||||
|
{
|
||||||
|
var dr = dt.NewRow();
|
||||||
|
foreach (var value in rowInfos)
|
||||||
|
{
|
||||||
|
if (value.Value != null && UtilMethods.GetUnderType(value.Value.GetType()) == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
if (value.Value != null && value.Value.ToString() == DateTime.MinValue.ToString())
|
||||||
|
{
|
||||||
|
value.Value = Convert.ToDateTime("1753/01/01");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (value.Value == null)
|
||||||
|
{
|
||||||
|
value.Value = DBNull.Value;
|
||||||
|
}
|
||||||
|
dr[value.DbColumnName] = value.Value;
|
||||||
|
}
|
||||||
|
dt.Rows.Add(dr);
|
||||||
|
}
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
private void CloseDb()
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||||
|
{
|
||||||
|
this.Context.Ado.Connection.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
using Dm;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
|
||||||
|
public class DmFastBuilder:FastBuilder,IFastBuilder
|
||||||
|
{
|
||||||
|
public override bool IsActionUpdateColumns { get; set; } = true;
|
||||||
|
public override DbFastestProperties DbFastestProperties { get; set; } = new DbFastestProperties() {
|
||||||
|
HasOffsetTime=true
|
||||||
|
};
|
||||||
|
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
DmBulkCopy bulkCopy = GetBulkCopyInstance();
|
||||||
|
bulkCopy.DestinationTableName = dt.TableName;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bulkCopy.WriteToServer(dt);
|
||||||
|
await Task.Delay(0);//No Support Async
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CloseDb();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
CloseDb();
|
||||||
|
return dt.Rows.Count;
|
||||||
|
}
|
||||||
|
public DmBulkCopy GetBulkCopyInstance()
|
||||||
|
{
|
||||||
|
DmBulkCopy copy;
|
||||||
|
if (this.Context.Ado.Transaction == null)
|
||||||
|
{
|
||||||
|
copy = new DmBulkCopy((DmConnection)this.Context.Ado.Connection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
copy = new DmBulkCopy((DmConnection)this.Context.Ado.Connection, DmBulkCopyOptions.Default, (DmTransaction)this.Context.Ado.Transaction);
|
||||||
|
}
|
||||||
|
if (this.Context.Ado.Connection.State == ConnectionState.Closed)
|
||||||
|
{
|
||||||
|
this.Context.Ado.Connection.Open();
|
||||||
|
}
|
||||||
|
copy.BulkCopyTimeout = this.Context.Ado.CommandTimeOut;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user