Update pgsql & 人大金仓

This commit is contained in:
sunkaixuan 2023-03-06 18:08:30 +08:00
parent 8364ea6b1d
commit 6c5b1de579
5 changed files with 19 additions and 6 deletions

View File

@ -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 + "";

View File

@ -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")
{

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);