Synchronization code

This commit is contained in:
sunkaixuan
2025-03-17 19:55:05 +08:00
parent 30c5be494b
commit f1733039d2
10 changed files with 57 additions and 4 deletions

View File

@@ -384,7 +384,7 @@ namespace SqlSugar
{ {
value = columnInfo.DefaultValue; value = columnInfo.DefaultValue;
} }
else if (columnInfo.DataType.ObjToString().ToLower().IsIn("int","int4","bigint","int8","int2")&& columnInfo.DefaultValue.IsInt()) else if (columnInfo.DataType.ObjToString().ToLower().IsIn("float","double","decimal","int","int4","bigint","int8","int2")&& columnInfo.DefaultValue.IsInt())
{ {
value = columnInfo.DefaultValue; value = columnInfo.DefaultValue;
} }

View File

@@ -211,19 +211,23 @@ namespace SqlSugar
} }
public ISugarQueryable<T, T2> LeftJoinIF<T2>(bool isLeftJoin, Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> LeftJoinIF<T2>(bool isLeftJoin, Expression<Func<T, T2, bool>> joinExpression)
{ {
var oldAsName = this.QueryBuilder.AsTables?.ToDictionary(it=>it.Key,it=>it.Value);
var result = LeftJoin(joinExpression); var result = LeftJoin(joinExpression);
if (isLeftJoin == false) if (isLeftJoin == false)
{ {
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last()); result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
result.QueryBuilder.AsTables = oldAsName;
} }
return result; return result;
} }
public ISugarQueryable<T, T2> InnerJoinIF<T2>(bool isJoin, Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> InnerJoinIF<T2>(bool isJoin, Expression<Func<T, T2, bool>> joinExpression)
{ {
var oldAsName = this.QueryBuilder.AsTables?.ToDictionary(it => it.Key, it => it.Value);
var result = InnerJoin(joinExpression); var result = InnerJoin(joinExpression);
if (isJoin == false) if (isJoin == false)
{ {
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last()); result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
result.QueryBuilder.AsTables = oldAsName;
} }
return result; return result;
} }

View File

@@ -538,7 +538,7 @@ namespace SqlSugar
break; break;
case DbType.HANA: case DbType.HANA:
Check.Exception(SugarCompatible.IsFramework, "NANA only support .net core"); Check.Exception(SugarCompatible.IsFramework, "NANA only support .net core");
InstanceFactory.CustomDllName = "SqlSugar.HanaConnector"; InstanceFactory.CustomDllName = "SqlSugar.HANAConnector";
break; break;
case DbType.Xugu: case DbType.Xugu:
Check.Exception(SugarCompatible.IsFramework, "Xugu only support .net core"); Check.Exception(SugarCompatible.IsFramework, "Xugu only support .net core");
@@ -549,6 +549,10 @@ namespace SqlSugar
case DbType.GoldenDB: case DbType.GoldenDB:
config.DbType = DbType.MySql; config.DbType = DbType.MySql;
break; break;
case DbType.DB2:
Check.Exception(SugarCompatible.IsFramework, "Db2 only support .net core");
InstanceFactory.CustomDllName = "SqlSugar.Db2Core";
break;
default: default:
throw new Exception("ConnectionConfig.DbType is null"); throw new Exception("ConnectionConfig.DbType is null");
} }

View File

@@ -36,6 +36,7 @@ namespace SqlSugar
TDSQLForPGODBC, TDSQLForPGODBC,
TDSQL, TDSQL,
HANA, HANA,
DB2,
Custom =900 Custom =900
} }
} }

View File

@@ -262,6 +262,16 @@ namespace SqlSugar
var value = GetNewExpressionValue(item); var value = GetNewExpressionValue(item);
parameter.Context.Result.Append($" {value} AS {asName} "); parameter.Context.Result.Append($" {value} AS {asName} ");
} }
else if (item is ConditionalExpression)
{
var value = GetNewExpressionValue(item);
parameter.Context.Result.Append($" {value} AS {asName} ");
}
else if (ExpressionTool.GetMethodName(item)==nameof(SqlFunc.IIF))
{
var value = GetNewExpressionValue(item);
parameter.Context.Result.Append($" {value} AS {asName} ");
}
else else
{ {
asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType); asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType);

View File

@@ -144,6 +144,10 @@ namespace SqlSugar
var leftString = GetNewExpressionValue(expression.Left); var leftString = GetNewExpressionValue(expression.Left);
var RightString = GetNewExpressionValue(expression.Right); var RightString = GetNewExpressionValue(expression.Right);
var joinString = this.Context.DbMehtods.MergeString(leftString, RightString); var joinString = this.Context.DbMehtods.MergeString(leftString, RightString);
if (this.Context is KdbndpExpressionContext&&this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel==DbType.SqlServer)
{
joinString = new SqlServerMethod().MergeString(leftString, RightString);
}
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
{ {
base.Context.Result.Replace("{0}", $" {joinString} "); base.Context.Result.Replace("{0}", $" {joinString} ");

View File

@@ -780,7 +780,14 @@ namespace SqlSugar
string shortName = expression.Expression.ToString(); string shortName = expression.Expression.ToString();
string fieldName = expression.Member.Name; string fieldName = expression.Member.Name;
fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName); fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName);
if (UtilMethods.GetMoreSetting(this.Context).IsCorrectErrorSqlParameterName)
{
fieldName = Context.GetTranslationColumnName(shortName) + UtilConstants.Dot + Context.GetTranslationColumnName(fieldName);
}
else
{
fieldName = Context.GetTranslationColumnName(shortName + UtilConstants.Dot + fieldName); fieldName = Context.GetTranslationColumnName(shortName + UtilConstants.Dot + fieldName);
}
return fieldName; return fieldName;
} }

View File

@@ -186,6 +186,10 @@ namespace SqlSugar
{ {
var asName = this.context.GetTranslationTableName(asItems.First().Replace(subKey, ""), false); var asName = this.context.GetTranslationTableName(asItems.First().Replace(subKey, ""), false);
var repKey = $"\\{this.context.SqlTranslationLeft}.+\\{this.context.SqlTranslationRight}"; var repKey = $"\\{this.context.SqlTranslationLeft}.+\\{this.context.SqlTranslationRight}";
if (this.context.IsSingle&&this.context.JoinIndex==0&&this.context.CurrentShortName.HasValue()&& isAsAttr&& !asName.Contains(this.context.CurrentShortName))
{
asName = asName + " " + this.context.CurrentShortName+" ";
}
sqlItems[i] = Regex.Replace(sqlItems[i], repKey, asName); sqlItems[i] = Regex.Replace(sqlItems[i], repKey, asName);
} }
} }
@@ -195,11 +199,17 @@ namespace SqlSugar
for (int i = 0; i < sqlItems.Count; i++) for (int i = 0; i < sqlItems.Count; i++)
{ {
if (sqlItems[i].StartsWith("FROM " + this.context.SqlTranslationLeft)) if (sqlItems[i].StartsWith("FROM " + this.context.SqlTranslationLeft))
{
if (isAsAttr&&sqlItems[i].EndsWith(this.context.CurrentShortName + " "))
{
}
else
{ {
sqlItems[i] = sqlItems[i] + " " + this.context.CurrentShortName + " "; sqlItems[i] = sqlItems[i] + " " + this.context.CurrentShortName + " ";
} }
} }
} }
}
private List<string> GetSubItems() private List<string> GetSubItems()
{ {

View File

@@ -436,6 +436,14 @@ namespace SqlSugar
{ {
return CustomNamespace + "."+CustomDbName + name; return CustomNamespace + "."+CustomDbName + name;
} }
else if (type == "HANA")
{
return InstanceFactory.CustomDllName + "." + type + name;
}
else if (type == "DB2")
{
return "SqlSugar.DB2."+ type+ name;
}
else else
{ {
//if (!string.IsNullOrEmpty(CustomDllName)) //if (!string.IsNullOrEmpty(CustomDllName))

View File

@@ -1821,5 +1821,10 @@ namespace SqlSugar
} }
return true; return true;
} }
internal static ConnMoreSettings GetMoreSetting(ExpressionContext context)
{
return context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings ?? new ConnMoreSettings();
}
} }
} }