mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
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:
parent
8022fa6b44
commit
884e21e1ca
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user