Browse Source

Update pgsql & 人大金仓

pull/31/head
sunkaixuan 2 years ago
parent
commit
6c5b1de579
  1. 10
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs
  2. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs
  3. 2
      Src/Asp.NetCore2/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpInsertBuilder.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs
  5. 7
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

10
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs

@ -304,7 +304,7 @@ namespace SqlSugar
GetDbColumnIndex++;
return pname;
}
else if (columnInfo.PropertyType!=null&&columnInfo.PropertyType.Name == "TimeOnly" && name != null && !name.ObjToString().StartsWith(Builder.SqlParameterKeyWord))
else if (columnInfo.PropertyType!=null&&columnInfo.PropertyType.Name == "TimeOnly" )
{
var timeSpan = UtilMethods.TimeOnlyToTimeSpan(columnInfo.Value);
var pname = Builder.SqlParameterKeyWord + columnInfo.DbColumnName + "_ts" + GetDbColumnIndex;
@ -312,6 +312,14 @@ namespace SqlSugar
GetDbColumnIndex++;
return pname;
}
else if (columnInfo.PropertyType != null && columnInfo.PropertyType.Name == "DateOnly")
{
var timeSpan = UtilMethods.DateOnlyToDateTime(columnInfo.Value);
var pname = Builder.SqlParameterKeyWord + columnInfo.DbColumnName + "_ts" + GetDbColumnIndex;
this.Parameters.Add(new SugarParameter(pname,Convert.ToDateTime(timeSpan)));
GetDbColumnIndex++;
return pname;
}
else
{
return name + "";

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs

@ -165,12 +165,12 @@ namespace SqlSugar
else if (type?.Name == "TimeOnly")
{
this.DbType = System.Data.DbType.Time;
this.Value = UtilMethods.TimeOnlyToTimeSpan(this.Value);
this.Value =UtilMethods.TimeOnlyToTimeSpan(this.Value);
}
else if (type?.Name == "DateOnly")
{
this.DbType = System.Data.DbType.Date;
this.Value = UtilMethods.DateOnlyToDateTime(this.Value);
this.Value =Convert.ToDateTime(UtilMethods.DateOnlyToDateTime(this.Value));
}
else if (type?.FullName == "Newtonsoft.Json.Linq.JObject" || type?.FullName == "Newtonsoft.Json.Linq.JArray" || type?.FullName == "Newtonsoft.Json.Linq.JValue")
{

2
Src/Asp.NetCore2/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpInsertBuilder.cs

@ -66,7 +66,7 @@ namespace SqlSugar
}
batchInsetrSql.Append("\r\n ( " + string.Join(",", columns.Select(it =>
{
if (it.InsertServerTime || it.InsertSql.HasValue())
if (it.InsertServerTime || it.InsertSql.HasValue() || it.SqlParameterDbType != null || it?.PropertyType?.Name == "DateOnly" || it?.PropertyType?.Name == "TimeOnly")
{
return GetDbColumn(it, null);
}

2
Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs

@ -75,7 +75,7 @@ namespace SqlSugar
}
batchInsetrSql.Append("\r\n ( " + string.Join(",", columns.Select(it =>
{
if (it.InsertServerTime || it.InsertSql.HasValue())
if (it.InsertServerTime || it.InsertSql.HasValue()||it.SqlParameterDbType!=null|| it?.PropertyType?.Name=="DateOnly" || it?.PropertyType?.Name == "TimeOnly")
{
return GetDbColumn(it, null);
}

7
Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

@ -104,7 +104,12 @@ namespace SqlSugar
{
destinationType = UtilMethods.GetUnderType(destinationType);
var sourceType = value.GetType();
if (destinationType.Name == "DateOnly"&&sourceType==typeof(string))
{
var type = Type.GetType("System.DateOnly", true, true);
var method = type.GetMethods().FirstOrDefault(it => it.GetParameters().Length == 1 && it.Name == "FromDateTime");
return method.Invoke(null, new object[] {Convert.ToDateTime(value)});
}
var destinationConverter = TypeDescriptor.GetConverter(destinationType);
if (destinationConverter != null && destinationConverter.CanConvertFrom(value.GetType()))
return destinationConverter.ConvertFrom(null, culture, value);

Loading…
Cancel
Save