mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Synchronized code
This commit is contained in:
parent
63ca791ad3
commit
feb6a58394
@ -298,6 +298,7 @@ namespace SqlSugar
|
||||
{
|
||||
pkName = "PK_" + pkName.GetNonNegativeHashCodeString();
|
||||
}
|
||||
columnName = string.Join(",", columnNames.Select(it=>SqlBuilder.GetTranslationColumnName(it)));
|
||||
string sql = string.Format(this.AddPrimaryKeySql, tableName,pkName, columnName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@ -23,7 +23,7 @@ namespace SqlSugar
|
||||
public DiffLogModel diffModel { get; set; }
|
||||
public List<string> tempPrimaryKeys { get; set; }
|
||||
internal Action RemoveCacheFunc { get; set; }
|
||||
internal List<T> DeleteObjects { get; set; }
|
||||
public List<T> DeleteObjects { get; set; }
|
||||
public EntityInfo EntityInfo
|
||||
{
|
||||
get
|
||||
@ -690,7 +690,7 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
|
||||
private void After(string sql)
|
||||
protected virtual void After(string sql)
|
||||
{
|
||||
if (this.IsEnableDiffLogEvent)
|
||||
{
|
||||
@ -711,7 +711,7 @@ namespace SqlSugar
|
||||
DataChangesAop(this.DeleteObjects);
|
||||
}
|
||||
|
||||
private void Before(string sql)
|
||||
protected virtual void Before(string sql)
|
||||
{
|
||||
if (this.IsEnableDiffLogEvent)
|
||||
{
|
||||
@ -727,7 +727,7 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private List<DiffLogTableInfo> GetDiffTable(string sql, List<SugarParameter> parameters)
|
||||
protected virtual List<DiffLogTableInfo> GetDiffTable(string sql, List<SugarParameter> parameters)
|
||||
{
|
||||
List<DiffLogTableInfo> result = new List<DiffLogTableInfo>();
|
||||
var whereSql = Regex.Replace(sql, ".* WHERE ", "", RegexOptions.Singleline);
|
||||
@ -756,7 +756,7 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void DataAop(object deleteObj)
|
||||
protected virtual void DataAop(object deleteObj)
|
||||
{
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataExecuting;
|
||||
if (deleteObj != null&& dataEvent!=null)
|
||||
@ -770,7 +770,7 @@ namespace SqlSugar
|
||||
dataEvent(deleteObj,model);
|
||||
}
|
||||
}
|
||||
private void DataChangesAop(List<T> deleteObjs)
|
||||
protected virtual void DataChangesAop(List<T> deleteObjs)
|
||||
{
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted;
|
||||
if(dataEvent != null&&deleteObjs != null)
|
||||
|
@ -181,12 +181,24 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
this._Context.Updateable(_Roots)
|
||||
.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent,_RootOptions.DiffLogBizData)
|
||||
.UpdateColumns(_RootOptions.UpdateColumns)
|
||||
.IgnoreColumns(_RootOptions.IgnoreColumns)
|
||||
.IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns)
|
||||
.ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock);
|
||||
if (_Roots.Count() == 1 && _RootOptions?.IsOptLock==true)
|
||||
{
|
||||
this._Context.Updateable(_Roots.First())
|
||||
.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData)
|
||||
.UpdateColumns(_RootOptions.UpdateColumns)
|
||||
.IgnoreColumns(_RootOptions.IgnoreColumns)
|
||||
.IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns)
|
||||
.ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._Context.Updateable(_Roots)
|
||||
.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData)
|
||||
.UpdateColumns(_RootOptions.UpdateColumns)
|
||||
.IgnoreColumns(_RootOptions.IgnoreColumns)
|
||||
.IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns)
|
||||
.ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_RootOptions != null && _RootOptions?.IsDiffLogEvent == true)
|
||||
|
@ -1703,6 +1703,7 @@ namespace SqlSugar
|
||||
var unionall = this.Context._UnionAll(tableQueryables.ToArray());
|
||||
unionall.QueryBuilder.Includes = this.QueryBuilder.Includes;
|
||||
unionall.QueryBuilder.EntityType = typeof(T);
|
||||
unionall.QueryBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter;
|
||||
if (unionall.QueryBuilder.Includes?.Any()==true)
|
||||
{
|
||||
unionall.QueryBuilder.NoCheckInclude = true;
|
||||
|
@ -551,6 +551,10 @@ namespace SqlSugar
|
||||
foreach (var item in whereColumns)
|
||||
{
|
||||
var value = item.PropertyInfo.GetValue(dataItem.Item, null);
|
||||
if (value is string str&&str=="null")
|
||||
{
|
||||
value = $"[null]";
|
||||
}
|
||||
if (value != null&&value.GetType().IsEnum())
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
|
||||
|
@ -528,6 +528,13 @@ namespace SqlSugar
|
||||
}
|
||||
if (item.IsJoinQuery == false||isMain||isSingle|| isEasyJoin)
|
||||
{
|
||||
if (item.IsJoinQuery == false&& ChildType.IsInterface)
|
||||
{
|
||||
foreach (var joinInfo in this.JoinQueryInfos)
|
||||
{
|
||||
sql = ReplaceFilterColumnName(sql, joinInfo.EntityType, Builder.GetTranslationColumnName(joinInfo.ShortName));
|
||||
}
|
||||
}
|
||||
WhereInfos.Add(sql);
|
||||
}
|
||||
else
|
||||
@ -993,7 +1000,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (IsSingle() && result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable") && TableShortName != null)
|
||||
{
|
||||
result = result.Replace(") MergeTable ", ") " + TableShortName+UtilConstants.Space);
|
||||
result = result.Replace(") MergeTable ", ") " +this.Builder.GetTranslationColumnName(TableShortName)+UtilConstants.Space);
|
||||
TableShortName = null;
|
||||
}
|
||||
if (IsSingle() && result.Contains("unionTable") && result.Trim().EndsWith(" unionTable")&& TableShortName!=null)
|
||||
|
@ -373,7 +373,14 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInVals() + ")");
|
||||
if (item.CSharpTypeName.EqualCase("nstring"))
|
||||
{
|
||||
inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInValsByVarchar() + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInVals() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return inValue1;
|
||||
@ -389,7 +396,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (item.FieldValue == "[null]")
|
||||
{
|
||||
item.FieldValue = "'null'";
|
||||
item.FieldValue = "null";
|
||||
}
|
||||
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName);
|
||||
parameters.Add(new SugarParameter(parameterName, GetFieldValue(item)));
|
||||
|
@ -497,6 +497,10 @@ namespace SqlSugar
|
||||
Check.Exception(SugarCompatible.IsFramework, "OceanBaseForOracle only support .net core");
|
||||
InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.OceanBaseForOracle" : "SqlSugar.OceanBaseForOracleCore";
|
||||
break;
|
||||
case DbType.TDSQLForPGODBC:
|
||||
Check.Exception(SugarCompatible.IsFramework, "TDSQLForPGODBC only support .net core");
|
||||
InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.TDSQLForPGODBC" : "SqlSugar.TDSQLForPGODBC";
|
||||
break;
|
||||
case DbType.GaussDB:
|
||||
config.DbType = DbType.PostgreSQL;
|
||||
if (this.CurrentConnectionConfig.MoreSettings == null)
|
||||
@ -518,6 +522,9 @@ namespace SqlSugar
|
||||
case DbType.PolarDB:
|
||||
config.DbType = DbType.MySql;
|
||||
break;
|
||||
case DbType.TDSQL:
|
||||
config.DbType = DbType.MySql;
|
||||
break;
|
||||
case DbType.Doris:
|
||||
config.DbType = DbType.MySql;
|
||||
if (this.CurrentConnectionConfig.MoreSettings == null)
|
||||
|
@ -97,7 +97,7 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private dynamic GetKey()
|
||||
private string GetKey()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(this.initkey) &&this.initThreadMainId == GetCurrentThreadId())
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
@ -614,7 +614,7 @@ namespace SqlSugar
|
||||
return mappInfo == null ? propertyName : mappInfo.DbColumnName;
|
||||
}
|
||||
}
|
||||
private List<string> GetPrimaryKeys()
|
||||
protected List<string> GetPrimaryKeys()
|
||||
{
|
||||
if (this.WhereColumnList.HasValue())
|
||||
{
|
||||
|
@ -36,5 +36,6 @@ namespace SqlSugar
|
||||
public int MaxParameterNameLength { get; set; }
|
||||
public bool DisableQueryWhereColumnRemoveTrim { get; set; }
|
||||
public DbType? DatabaseModel { get;set; }
|
||||
public bool ClickHouseEnableFinal { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ namespace SqlSugar
|
||||
Doris,
|
||||
Xugu,
|
||||
GoldenDB,
|
||||
TDSQLForPGODBC,
|
||||
TDSQL,
|
||||
Custom =900
|
||||
}
|
||||
}
|
||||
|
@ -1228,5 +1228,9 @@ namespace SqlSugar
|
||||
|
||||
return queryCondition;
|
||||
}
|
||||
public virtual string SelectFields(MethodCallExpressionModel model)
|
||||
{
|
||||
return string.Join(",", model.Args.Select(it => it.MemberName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,5 +128,6 @@ namespace SqlSugar
|
||||
string NewUid(MethodCallExpressionModel mode);
|
||||
string FullTextContains(MethodCallExpressionModel mode);
|
||||
string PgsqlArrayContains(MethodCallExpressionModel model);
|
||||
string SelectFields(MethodCallExpressionModel model);
|
||||
}
|
||||
}
|
||||
|
@ -431,5 +431,25 @@ namespace SqlSugar
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static void SelectFields(string fieldName1)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static void SelectFields(string fieldName1,string fieldName2)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static void SelectFields(string fieldName1, string fieldName2, string fieldName3)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static void SelectFields(string fieldName1, string fieldName2, string fieldName3, string fieldName4)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static void SelectFields(string fieldName1, string fieldName2, string fieldName3, string fieldName4, string fieldName5)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace SqlSugar
|
||||
public const string CodeFirst_BigString = "varcharmax,longtext,text,clob";
|
||||
public static string CodeFirst_MySqlCollate{get;set;}
|
||||
public static string CodeFirst_MySqlTableEngine { get; set; }
|
||||
public static Type Backup_MySqlBackupType { get; set; }
|
||||
|
||||
public static Func<long> CustomSnowFlakeFunc;
|
||||
public static Func<long> CustomSnowFlakeTimeErrorFunc;
|
||||
|
@ -18,6 +18,17 @@ namespace SqlSugar
|
||||
return string.Join(",", array.Where(c => c != null).Select(it => it.ToSqlValue()));
|
||||
}
|
||||
}
|
||||
public static string ToJoinSqlInValsByVarchar<T>(this T[] array)
|
||||
{
|
||||
if (array == null || array.Length == 0)
|
||||
{
|
||||
return ToSqlValue(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Join(",", array.Where(c => c != null).Select(it => "N"+it.ToSqlValue()));
|
||||
}
|
||||
}
|
||||
public static string ToJoinSqlInValsN<T>(this T[] array)
|
||||
{
|
||||
if (array == null || array.Length == 0)
|
||||
|
@ -711,7 +711,8 @@ namespace SqlSugar
|
||||
MaxParameterNameLength=it.MoreSettings.MaxParameterNameLength,
|
||||
DisableQueryWhereColumnRemoveTrim=it.MoreSettings.DisableQueryWhereColumnRemoveTrim,
|
||||
DatabaseModel=it.MoreSettings.DatabaseModel,
|
||||
EnableILike=it.MoreSettings.EnableILike
|
||||
EnableILike=it.MoreSettings.EnableILike,
|
||||
ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal
|
||||
|
||||
},
|
||||
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
||||
@ -1392,6 +1393,14 @@ namespace SqlSugar
|
||||
{
|
||||
return Convert.ToInt64(item.FieldValue);
|
||||
}
|
||||
else if (item.CSharpTypeName.EqualCase("float"))
|
||||
{
|
||||
return Convert.ToSingle(item.FieldValue);
|
||||
}
|
||||
else if (item.CSharpTypeName.EqualCase("single"))
|
||||
{
|
||||
return Convert.ToSingle(item.FieldValue);
|
||||
}
|
||||
else if (item.CSharpTypeName.EqualCase("short"))
|
||||
{
|
||||
return Convert.ToInt16(item.FieldValue);
|
||||
|
Loading…
Reference in New Issue
Block a user