Synchronization code

This commit is contained in:
sunkaixuan
2024-04-23 10:59:51 +08:00
parent 01ee9be1a2
commit fb88592915
2 changed files with 21 additions and 2 deletions

View File

@@ -1559,7 +1559,7 @@ namespace SqlSugar
} }
else if (item.Value is byte[]&&connectionConfig.DbType==DbType.PostgreSQL) else if (item.Value is byte[]&&connectionConfig.DbType==DbType.PostgreSQL)
{ {
result = result.Replace(item.ParameterName, "E'0x" + BitConverter.ToString((byte[])item.Value).Replace("-", "")+"'" ); result = result.Replace(item.ParameterName, ByteArrayToPostgreByteaLiteral(item.Value as byte[]));
} }
else if (item.Value is byte[]) else if (item.Value is byte[])
{ {
@@ -1595,7 +1595,26 @@ namespace SqlSugar
return result; return result;
} }
public static string ByteArrayToPostgreByteaLiteral(byte[] data)
{
var sb = new StringBuilder("E'");
foreach (var b in data)
{
if (b >= 32 && b < 127 && !char.IsControl((char)b)) // 可打印的ASCII字符
{
sb.Append((char)b);
}
else // 非打印字符或控制字符
{
sb.Append("\\\\");
sb.Append(Convert.ToString(b, 8).PadLeft(3, '0'));
}
}
sb.Append("'::bytea");
return sb.ToString();
}
public static void CheckArray<T>(T[] insertObjs) where T : class, new() public static void CheckArray<T>(T[] insertObjs) where T : class, new()
{ {

View File

@@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>SqlSugarCore</id> <id>SqlSugarCore</id>
<version>5.1.4.153-preview25</version> <version>5.1.4.153-preview26</version>
<authors>sunkaixuan</authors> <authors>sunkaixuan</authors>
<owners>果糖大数据科技</owners> <owners>果糖大数据科技</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>