- 完善 [Column(MapType = typeof(byte[]))] 对 Guid/string 的映射支持;

This commit is contained in:
28810
2020-01-07 00:41:22 +08:00
parent fbbd74f54c
commit 5afeea7711
33 changed files with 128 additions and 135 deletions

View File

@ -40,6 +40,7 @@ namespace FreeSql.PostgreSQL
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || mapType.IsArrayOrList() || param is JToken || param is JObject || param is JArray))
param = Utils.GetDataReaderValue(mapType, param);
bool isdic;
if (param is bool || param is bool?)
return (bool)param ? "'t'" : "'f'";
@ -53,6 +54,8 @@ namespace FreeSql.PostgreSQL
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'");
else if (param is TimeSpan || param is TimeSpan?)
return ((TimeSpan)param).Ticks / 10;
else if (param is byte[])
return $"'\\x{CommonUtils.BytesSqlRaw(param as byte[])}'";
else if (param is JToken || param is JObject || param is JArray)
return string.Concat("'", param.ToString().Replace("'", "''"), "'::jsonb");
else if ((isdic = param is Dictionary<string, string>) ||

View File

@ -156,15 +156,8 @@ namespace FreeSql.PostgreSQL
}
value = getParamterValue(type, value);
var type2 = value.GetType();
if (type2 == typeof(byte[]))
{
var bytes = value as byte[];
var sb = new StringBuilder().Append("'\\x");
foreach (var vc in bytes)
sb.Append(vc.ToString("X").PadLeft(2, '0'));
return sb.Append("'").ToString(); //val = Encoding.UTF8.GetString(val as byte[]);
}
else if (type2 == typeof(TimeSpan) || type2 == typeof(TimeSpan?))
if (type2 == typeof(byte[])) return $"'\\x{CommonUtils.BytesSqlRaw(value as byte[])}'";
if (type2 == typeof(TimeSpan) || type2 == typeof(TimeSpan?))
{
var ts = (TimeSpan)value;
return $"'{Math.Min(24, (int)Math.Floor(ts.TotalHours))}:{ts.Minutes}:{ts.Seconds}'";