From 0adad53602770205b93263f43556bf9871afaeb4 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Tue, 7 Dec 2021 20:05:33 +0800 Subject: [PATCH] Support Oracle DateTimeOffset --- Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs | 10 ++++++++++ .../SqlSugar/Realization/Oracle/OracleProvider.cs | 5 +++++ .../Oracle/SqlBuilder/OracleInsertBuilder.cs | 9 +++++++-- .../Oracle/SqlBuilder/OracleUpdateBuilder.cs | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs index 79f02c374..f8f8c3f00 100644 --- a/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs @@ -28,6 +28,16 @@ namespace OrmTest }); // db.Utilities.RemoveCacheAll(); var xxxxx = Db.DbMaintenance.GetColumnInfosByTableName("TESTA1", false); + Db.CodeFirst.InitTables(); + Db.Insertable(new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }).ExecuteCommand(); + Db.Insertable(new List { new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand(); + var list2 = Db.Queryable().ToList(); + + } + [SqlSugar.SugarTable("UnitDateOfTime2211")] + public class UnitDateOfTime22 + { + public DateTimeOffset DateTimeOffset1 { get; set; } } public class TESTA1 { public string X { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs index b1fade80a..fbc47602b 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs @@ -143,6 +143,11 @@ namespace SqlSugar sqlParameter.DbType = System.Data.DbType.String; sqlParameter.Value = sqlParameter.Value.ObjToString(); } + else if (parameter.DbType == System.Data.DbType.DateTimeOffset) + { + sqlParameter.Value = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)parameter.Value); + sqlParameter.DbType = System.Data.DbType.DateTime; + } else if (parameter.DbType == System.Data.DbType.Boolean) { sqlParameter.DbType = System.Data.DbType.Int16; diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs index 0668f157e..d11af9d7e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs @@ -134,14 +134,19 @@ namespace SqlSugar else if (type == UtilConstants.BoolType) { return value.ObjToBool() ? "1" : "0"; + } + else if (type==UtilConstants.DateTimeOffsetType) + { + var date= UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value); + return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') "; } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { - return N+"'" + value.ToString().ToSqlFilter() + "'"; + return N + "'" + value.ToString().ToSqlFilter() + "'"; } else { - return N+"'" + value.ToString() + "'"; + return N + "'" + value.ToString() + "'"; } } } diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs index dd63635de..2eb282f3e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs @@ -76,6 +76,11 @@ namespace SqlSugar { return value.ObjToBool() ? "1" : "0"; } + else if (type == UtilConstants.DateTimeOffsetType) + { + var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value); + return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') "; + } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { return N + "'" + value.ToString().ToSqlFilter() + "'";