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

menghaoran 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 b8302de  #7792, fix postgresql insert statement result (#7804)
b8302de is described below

commit b8302dece09bc43f45220f26b2b26bdbc51298c0
Author: Zhang Yonglun <[email protected]>
AuthorDate: Fri Oct 16 14:40:38 2020 +0800

    #7792, fix postgresql insert statement result (#7804)
---
 .../packet/generic/PostgreSQLCommandCompletePacket.java |  6 +++++-
 .../generic/PostgreSQLCommandCompletePacketTest.java    | 17 +++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
index b401503..317fb5d 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
@@ -46,6 +46,10 @@ public final class PostgreSQLCommandCompletePacket 
implements PostgreSQLPacket {
     
     @Override
     public void write(final PostgreSQLPacketPayload payload) {
-        payload.writeStringNul(sqlCommand + " " + rowCount);
+        if ("INSERT".equals(sqlCommand)) {
+            payload.writeStringNul(sqlCommand + " 0 " + rowCount);
+        } else {
+            payload.writeStringNul(sqlCommand + " " + rowCount);
+        }
     }
 }
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
index 0a302d8..e5ce8dd 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertThat;
 public final class PostgreSQLCommandCompletePacketTest {
     
     @Test
-    public void assertReadWrite() {
-        String sqlCommand = "SELECT * FROM t_order LIMIT 1";
+    public void assertSelectReadWrite() {
+        String sqlCommand = "SELECT";
         long rowCount = 1;
         String expectedString = sqlCommand + " " + rowCount;
         int expectedStringLength = expectedString.length();
@@ -39,4 +39,17 @@ public final class PostgreSQLCommandCompletePacketTest {
         packet.write(payload);
         assertThat(payload.readStringNul(), is(expectedString));
     }
+    
+    @Test
+    public void assertInsertReadWrite() {
+        String sqlCommand = "INSERT";
+        long rowCount = 1;
+        String expectedString = sqlCommand + " 0 " + rowCount;
+        int expectedStringLength = expectedString.length();
+        PostgreSQLPacketPayload payload = new 
PostgreSQLPacketPayload(ByteBufTestUtils.createByteBuf(expectedStringLength + 
1));
+        PostgreSQLCommandCompletePacket packet = new 
PostgreSQLCommandCompletePacket(sqlCommand, rowCount);
+        assertThat(packet.getMessageType(), 
is(PostgreSQLCommandPacketType.COMMAND_COMPLETE.getValue()));
+        packet.write(payload);
+        assertThat(payload.readStringNul(), is(expectedString));
+    }
 }

Reply via email to