Skip to content

Commit 2c4c7c3

Browse files
Command complete information has been enriched
1 parent a3d44a8 commit 2c4c7c3

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/main/java/com/github/pgasync/io/backend/CommandCompleteDecoder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ public byte getMessageId() {
5454
@Override
5555
public CommandComplete read(ByteBuffer buffer, Charset encoding) {
5656
String tag = getCString(buffer, encoding);
57-
return new CommandComplete(tag);
57+
int affectedRows;
58+
if (tag.contains("INSERT") || tag.contains("UPDATE") || tag.contains("DELETE")) {
59+
String[] parts = tag.split(" ");
60+
affectedRows = Integer.parseInt(parts[parts.length - 1]);
61+
} else {
62+
affectedRows = 0;
63+
}
64+
return new CommandComplete(tag, affectedRows);
5865
}
5966

6067
}

src/main/java/com/github/pgasync/message/backend/CommandComplete.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717
import com.github.pgasync.message.Message;
1818

1919
/**
20-
* @author Antti Laisi
20+
* @author Antti Laisi
2121
*/
2222
public class CommandComplete implements Message {
2323

24+
private final String tag;
2425
private final int affectedRows;
2526

26-
public CommandComplete(String tag) {
27-
if (tag.contains("INSERT") || tag.contains("UPDATE") || tag.contains("DELETE")) {
28-
String[] parts = tag.split(" ");
29-
affectedRows = Integer.parseInt(parts[parts.length - 1]);
30-
} else {
31-
affectedRows = 0;
32-
}
27+
public CommandComplete(String tag, int affectedRows) {
28+
this.tag = tag;
29+
this.affectedRows = affectedRows;
30+
}
31+
32+
public String getTag() {
33+
return tag;
3334
}
3435

3536
public int getAffectedRows() {
@@ -38,6 +39,9 @@ public int getAffectedRows() {
3839

3940
@Override
4041
public String toString() {
41-
return String.format("CommandComplete(affectedRows=%d)", affectedRows);
42+
return "CommandComplete(" +
43+
"tag='" + tag + '\'' +
44+
", affectedRows=" + affectedRows +
45+
')';
4246
}
4347
}

0 commit comments

Comments
 (0)