You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/06/07 13:14:31 UTC

[shardingsphere] branch master updated: Correct PostgreSQL Bind Packet data row type (#10706)

This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b2faef  Correct PostgreSQL Bind Packet data row type (#10706)
3b2faef is described below

commit 3b2faef9723627f38d24f371a880cc580d6b3320
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Mon Jun 7 21:13:49 2021 +0800

    Correct PostgreSQL Bind Packet data row type (#10706)
---
 .../query/binary/bind/PostgreSQLComBindPacket.java     | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
index 44442a3..7e902c1 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
@@ -62,11 +62,7 @@ public final class PostgreSQLComBindPacket extends PostgreSQLCommandPacket {
         PostgreSQLBinaryStatement binaryStatement = PostgreSQLBinaryStatementRegistry.getInstance().get(connectionId).getBinaryStatement(statementId);
         sql = null == binaryStatement ? null : binaryStatement.getSql();
         parameters = null == sql ? Collections.emptyList() : getParameters(payload, parameterFormats, binaryStatement.getColumnTypes());
-        int resultFormatsLength = payload.readInt2();
-        binaryRowData = parameterFormats.contains(1);
-        for (int i = 0; i < resultFormatsLength; i++) {
-            payload.readInt2();
-        }
+        binaryRowData = isBinaryRowData(payload);
     }
     
     private List<Object> getParameters(final PostgreSQLPacketPayload payload, final List<Integer> parameterFormats, final List<PostgreSQLBinaryColumnType> columnTypes) {
@@ -143,6 +139,18 @@ public final class PostgreSQLComBindPacket extends PostgreSQLCommandPacket {
         return binaryProtocolValue.read(payload, parameterValueLength);
     }
     
+    private boolean isBinaryRowData(final PostgreSQLPacketPayload payload) {
+        int resultFormatsLength = payload.readInt2();
+        if (0 == resultFormatsLength) {
+            return false;
+        }
+        List<Integer> resultFormats = new ArrayList<>(resultFormatsLength);
+        for (int i = 0; i < resultFormatsLength; i++) {
+            resultFormats.add(payload.readInt2());
+        }
+        return resultFormats.stream().allMatch(each -> 1 == each);
+    }
+    
     @Override
     public void write(final PostgreSQLPacketPayload payload) {
     }