From 7ca313d842fd894571124ae8bcb9956512f584da Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 28 Mar 2025 16:53:35 +0800 Subject: [PATCH] Synchronization code --- .../Dm/DbMaintenance/DmDbMaintenance.cs | 8 +++ .../Dm/SqlBuilder/DmUpdateBuilder.cs | 8 +++ .../DbMaintenance/KdbndpDbMaintenance.cs | 8 ++- .../Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs | 6 +- .../SqlBuilder/PostgreSQLInsertBuilder.cs | 57 +++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Realization/Dm/DbMaintenance/DmDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Dm/DbMaintenance/DmDbMaintenance.cs index 2e595c269..3787e1b61 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Dm/DbMaintenance/DmDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Dm/DbMaintenance/DmDbMaintenance.cs @@ -653,11 +653,19 @@ WHERE upper(t.TABLE_NAME) = upper('{tableName}') private static void ConvertCreateColumnInfo(DbColumnInfo x) { string[] array = new string[] { "int" }; + if (x.OracleDataType.HasValue()) + { + x.DataType = x.OracleDataType; + } if (array.Contains(x.DataType?.ToLower())) { x.Length = 0; x.DecimalDigits = 0; } + if (x.DecimalDigits > 0 && x.DataType?.ToLower()?.IsIn("varchar", "clob", "varchar2", "nvarchar2", "nvarchar") == true) + { + x.DecimalDigits = 0; + } } #endregion } diff --git a/Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs index 7a9ffe9b6..254a60115 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmUpdateBuilder.cs @@ -28,6 +28,14 @@ namespace SqlSugar var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Where(s => OldPrimaryKeys == null || !OldPrimaryKeys.Contains(s.DbColumnName)).Select(m => GetOracleUpdateColums(i, m)).ToArray()); var pkList = t.Where(s => s.IsPrimarykey).ToList(); + if (this.IsWhereColumns && this.PrimaryKeys?.Any() == true) + { + var whereColumns = pkList.Where(it => this.PrimaryKeys?.Any(p => p.EqualCase(it.PropertyName) || p.EqualCase(it.DbColumnName)) == true).ToList(); + if (whereColumns.Any()) + { + pkList = whereColumns; + } + } List whereList = new List(); foreach (var item in pkList) { diff --git a/Src/Asp.Net/SqlSugar/Realization/Kdbndp/DbMaintenance/KdbndpDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Kdbndp/DbMaintenance/KdbndpDbMaintenance.cs index 33c4ff0af..2069345d7 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Kdbndp/DbMaintenance/KdbndpDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Kdbndp/DbMaintenance/KdbndpDbMaintenance.cs @@ -84,9 +84,15 @@ namespace SqlSugar cast(obj_description(relfilenode,'pg_class') as varchar) as Description from pg_class c where relkind = 'r' and c.oid >= 16384 and c.relnamespace != 99 and c.relname not like '%pl_profiler_saved%' order by relname"; } - return @"select cast(relname as varchar) as Name, + var result= @"select cast(relname as varchar) as Name, cast(obj_description(relfilenode,'pg_class') as varchar) as Description from sys_class c where relkind = 'r' and c.oid >= 16384 and c.relnamespace != 99 and c.relname not like '%pl_profiler_saved%' order by relname"; + + if (IsSqlServerModel()) + { + result = result.Replace(" as varchar)", " as varchar(max))"); + } + return result; } } protected override string GetViewInfoListSql diff --git a/Src/Asp.Net/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs index d0a6a900b..f2cfdcc43 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs @@ -163,7 +163,11 @@ namespace SqlSugar } if (IsSqlServerModel()) { - if (dbType == "varchar") + if (dbType == "numeric") + { + dbType = "numeric(18,6)"; + } + else if (dbType == "varchar") { dbType = "varchar(max)"; } diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs index d0a3af9f1..6d2d7742c 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs @@ -178,6 +178,63 @@ namespace SqlSugar } } } + public override object FormatValue(object value) + { + var N = string.Empty; + if (value == null) + { + return "NULL"; + } + else + { + var type = UtilMethods.GetUnderType(value.GetType()); + if (type == UtilConstants.DateType) + { + var date = value.ObjToDate(); + if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig)) + { + date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig); + } + return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'"; + } + else if (type == UtilConstants.ByteArrayType) + { + string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", ""); + return bytesString; + } + else if (type.IsEnum()) + { + if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) + { + return value.ToSqlValue(); + } + else + { + return Convert.ToInt64(value); + } + } + else if (type == UtilConstants.BoolType) + { + return value.ObjToBool() ? "1" : "0"; + } + else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) + { + return N + "'" + value.ToString().ToSqlFilter() + "'"; + } + else if (type == UtilConstants.DateTimeOffsetType) + { + return FormatDateTimeOffset(value); + } + else if (type == UtilConstants.FloatType) + { + return N + "'" + Convert.ToDouble(value).ToString() + "'"; + } + else + { + return N + "'" + value.ToString() + "'"; + } + } + } public override string FormatDateTimeOffset(object value) { return "'" + ((DateTimeOffset)value).ToString("o") + "'";