Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streaming Replication - 2nd] Fix affected rows parsing in CommandCompleteMessage #52

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/src/server_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,33 @@ class NotificationResponseMessage extends ServerMessage {
class CommandCompleteMessage extends ServerMessage {
final int rowsAffected;

static RegExp identifierExpression = RegExp(r'[A-Z ]*');
/// Match the digits at the end of the string.
isoos marked this conversation as resolved.
Show resolved Hide resolved
/// Possible values are:
/// ```
/// command-tag | #rows
/// SELECT 1
/// UPDATE 1234
/// DELETE 568
/// MOVE 42
/// FETCH 60
/// COPY 314
/// ```
/// For INSERT, there are three columns:
/// ```
/// | command tag | oid* | #rows |
/// INSERT 0 42
/// ```
/// *oid is only used with `INSERT` and it's always 0.
static RegExp identifierExpression = RegExp(r'\d+$');
isoos marked this conversation as resolved.
Show resolved Hide resolved

CommandCompleteMessage._(this.rowsAffected);

factory CommandCompleteMessage(Uint8List bytes) {
final str = utf8.decode(bytes.sublist(0, bytes.length - 1));
final match = identifierExpression.firstMatch(str);
var rowsAffected = 0;
if (match != null && match.end < str.length) {
rowsAffected = int.parse(str.split(' ').last);
if (match != null) {
rowsAffected = int.parse(match.group(0)!);
}
return CommandCompleteMessage._(rowsAffected);
}
Expand Down