Refactor addCommandComplete

Refactors addCommandComplete to tighten parsing regex start anchor and
handle edge case where no row count is specified (pre 8.2 COPY).
This commit is contained in:
Sehrope Sarkuni 2017-08-19 09:29:36 -04:00 committed by Brian C
parent 8022fa6b44
commit 884e21e1ca
2 changed files with 7 additions and 5 deletions

View File

@ -27,7 +27,7 @@ var Result = function (rowMode) {
}
}
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/
var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/
// adds a command complete message
Result.prototype.addCommandComplete = function (msg) {
@ -41,12 +41,12 @@ Result.prototype.addCommandComplete = function (msg) {
}
if (match) {
this.command = match[1]
// match 3 will only be existing on insert commands
if (match[3]) {
// msg.value is from native bindings
this.rowCount = parseInt(match[3] || msg.value, 10)
// COMMMAND OID ROWS
this.oid = parseInt(match[2], 10)
} else {
this.rowCount = parseInt(match[3], 10)
} else if (match[2]) {
// COMMAND ROWS
this.rowCount = parseInt(match[2], 10)
}
}

View File

@ -35,3 +35,5 @@ testForTag('INSERT 841 1', check(841, 1, 'INSERT'))
testForTag('DELETE 10', check(null, 10, 'DELETE'))
testForTag('UPDATE 11', check(null, 11, 'UPDATE'))
testForTag('SELECT 20', check(null, 20, 'SELECT'))
testForTag('COPY', check(null, null, 'COPY'))
testForTag('COPY 12345', check(null, 12345, 'COPY'))