mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 完善 [Column(MapType = typeof(byte[]))] 对 Guid/string 的映射支持;
This commit is contained in:
@ -39,6 +39,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
if (param == null) return "NULL";
|
||||
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || mapType.IsArrayOrList()))
|
||||
param = Utils.GetDataReaderValue(mapType, param);
|
||||
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? "'t'" : "'f'";
|
||||
else if (param is string || param is char)
|
||||
@ -51,6 +52,8 @@ namespace FreeSql.Odbc.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 IEnumerable)
|
||||
return AddslashesIEnumerable(param, mapType, mapColumn);
|
||||
|
||||
|
@ -124,15 +124,8 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
if (value == null) return "NULL";
|
||||
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}'";
|
||||
|
Reference in New Issue
Block a user