Synchronized code

This commit is contained in:
sunkaixuan 2024-11-01 19:11:29 +08:00
parent 63ca791ad3
commit feb6a58394
18 changed files with 108 additions and 20 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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)));

View File

@ -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)

View File

@ -97,7 +97,7 @@ namespace SqlSugar
}
return result;
}
private dynamic GetKey()
private string GetKey()
{
if (!string.IsNullOrEmpty(this.initkey) &&this.initThreadMainId == GetCurrentThreadId())
{

View File

@ -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())
{

View File

@ -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; }
}
}

View File

@ -33,6 +33,8 @@ namespace SqlSugar
Doris,
Xugu,
GoldenDB,
TDSQLForPGODBC,
TDSQL,
Custom =900
}
}

View File

@ -1228,5 +1228,9 @@ namespace SqlSugar
return queryCondition;
}
public virtual string SelectFields(MethodCallExpressionModel model)
{
return string.Join(",", model.Args.Select(it => it.MemberName));
}
}
}

View File

@ -128,5 +128,6 @@ namespace SqlSugar
string NewUid(MethodCallExpressionModel mode);
string FullTextContains(MethodCallExpressionModel mode);
string PgsqlArrayContains(MethodCallExpressionModel model);
string SelectFields(MethodCallExpressionModel model);
}
}

View File

@ -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");
}
}
}

View File

@ -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;

View File

@ -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)

View File

@ -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);