From 91896290f6a56a96b7a4e42c63ce8074d7e42c72 Mon Sep 17 00:00:00 2001 From: zhangting Date: Tue, 10 Sep 2024 17:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86raw=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=A0=BC=E5=BC=8F=E4=B8=8Eblob=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/postgresql/jdbc/PgResultSet.java | 3 +- .../postgresql/test/dolphintest/RawTest.java | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 pgjdbc/src/test/java/org/postgresql/test/dolphintest/RawTest.java diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java index 8fdf10b..d8d443f 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java @@ -2097,7 +2097,8 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS if (connection.unwrap(PgConnection.class).isDolphinCmpt()) { return new String(toBytes(result)); } - } else if (blobSet.contains(typeName)) { + } else if (blobSet.contains(typeName) || ("raw".equals(typeName) + && connection.getPgDatabase().isDolphin())) { return new String(toBytes(result)); } else if ("time".equals(typeName)) { char[] cs = result.toCharArray(); diff --git a/pgjdbc/src/test/java/org/postgresql/test/dolphintest/RawTest.java b/pgjdbc/src/test/java/org/postgresql/test/dolphintest/RawTest.java new file mode 100644 index 0000000..bcf92ed --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/test/dolphintest/RawTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.postgresql.test.dolphintest; + +import org.junit.Test; +import org.postgresql.test.TestUtil; +import org.postgresql.test.jdbc2.BaseTest4B; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * test raw + * + * @author zhangting + * @since 2024-09-10 + */ +public class RawTest extends BaseTest4B { + /* + * test raw type + */ + @Test + public void testRaw() throws Exception { + TestUtil.createTable(con, "test_raw", "c1 blob,c2 raw,c3 bytea"); + try (Statement statement = con.createStatement()) { + statement.execute("set bytea_output=escape;"); + statement.execute("INSERT INTO test_raw VALUES (empty_blob(),hextoraw('deadbeef'),e'\\\\xdeadbeef')"); + statement.execute("INSERT INTO test_raw VALUES ('null','null','null')"); + } + + String sql = "select c1,c2,c3 from test_raw"; + try (PreparedStatement pstmt = con.prepareStatement(sql); + ResultSet rs = pstmt.executeQuery()) { + assertTrue(rs.next()); + assertEquals("", rs.getString(1)); + assertEquals("deadbeef", rs.getString(2)); + assertEquals("\\336\\255\\276\\357", rs.getString(3)); + + assertTrue(rs.next()); + assertEquals("null", rs.getString(1)); + assertEquals("null", rs.getString(2)); + assertEquals("null", rs.getString(3)); + } + TestUtil.dropTable(con, "test_raw"); + } +} -- Gitee