Skip to content

Commit 884e21e

Browse files
sehropebrianc
authored andcommitted
Refactor addCommandComplete
Refactors addCommandComplete to tighten parsing regex start anchor and handle edge case where no row count is specified (pre 8.2 COPY).
1 parent 8022fa6 commit 884e21e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/result.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var Result = function (rowMode) {
2727
}
2828
}
2929

30-
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/
30+
var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/
3131

3232
// adds a command complete message
3333
Result.prototype.addCommandComplete = function (msg) {
@@ -41,12 +41,12 @@ Result.prototype.addCommandComplete = function (msg) {
4141
}
4242
if (match) {
4343
this.command = match[1]
44-
// match 3 will only be existing on insert commands
4544
if (match[3]) {
46-
// msg.value is from native bindings
47-
this.rowCount = parseInt(match[3] || msg.value, 10)
45+
// COMMMAND OID ROWS
4846
this.oid = parseInt(match[2], 10)
49-
} else {
47+
this.rowCount = parseInt(match[3], 10)
48+
} else if (match[2]) {
49+
// COMMAND ROWS
5050
this.rowCount = parseInt(match[2], 10)
5151
}
5252
}

test/unit/client/result-metadata-tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ testForTag('INSERT 841 1', check(841, 1, 'INSERT'))
3535
testForTag('DELETE 10', check(null, 10, 'DELETE'))
3636
testForTag('UPDATE 11', check(null, 11, 'UPDATE'))
3737
testForTag('SELECT 20', check(null, 20, 'SELECT'))
38+
testForTag('COPY', check(null, null, 'COPY'))
39+
testForTag('COPY 12345', check(null, 12345, 'COPY'))

0 commit comments

Comments
 (0)