Browse Source

Support Oracle DateTimeOffset

pull/10/MERGE
sunkaixuna 3 years ago
parent
commit
0adad53602
  1. 10
      Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs
  2. 5
      Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs
  3. 9
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs
  4. 5
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs

10
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<UnitDateOfTime22>();
Db.Insertable(new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }).ExecuteCommand();
Db.Insertable(new List<UnitDateOfTime22> { new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
var list2 = Db.Queryable<UnitDateOfTime22>().ToList();
}
[SqlSugar.SugarTable("UnitDateOfTime2211")]
public class UnitDateOfTime22
{
public DateTimeOffset DateTimeOffset1 { get; set; }
}
public class TESTA1 {
public string X { get; set; }

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

9
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() + "'";
}
}
}

5
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() + "'";

Loading…
Cancel
Save