result of query contains metadata about query execution

This commit is contained in:
brianc 2011-01-19 00:35:32 -06:00
parent 31b5f82ad0
commit 56ba2567ce
4 changed files with 44 additions and 10 deletions

View File

@ -85,7 +85,7 @@ p.submit = function(connection) {
connection.removeListener('error', onError);
connection.removeListener('commandComplete', onCommandComplete);
if(self.callback) {
self.callback(null, {rows: rows});
self.callback(null, result);
rows = [];
}
self.emit('end', result);

View File

@ -7,14 +7,21 @@ var Result = function() {
var p = Result.prototype;
var matchRegexp = /([A-Za-z]+) (\d+ )?(\d+)?/
//adds a command complete message
p.addCommandComplete = function(msg) {
var splitMsg = msg.text.split(' ');
this.commandType = splitMsg.shift();
this.rowCount = splitMsg.pop();
//with INSERT we have oid in the middle
if(splitMsg.length) {
this.oid = splitMsg[0];
var match = matchRegexp.exec(msg.text);
if(match) {
this.command = match[1];
//match 3 will only be existing on insert commands
if(match[3]) {
this.rowCount = parseInt(match[3]);
this.oid = parseInt(match[2]);
} else {
this.rowCount = parseInt(match[2]);
}
}
};

View File

@ -0,0 +1,25 @@
var helper = require(__dirname + "/test-helper");
var pg = helper.pg;
var conString = helper.connectionString();
pg.connect(conString, assert.calls(function(err, client) {
assert.isNull(err);
client.query("CREATE TEMP TABLE zugzug(name varchar(10))", assert.calls(function(err, result) {
assert.isNull(err);
//let's list this as ignored for now
// process.nextTick(function() {
// test('should identify "CREATE TABLE" message', function() {
// return false;
// assert.equal(result.command, "CREATE TABLE");
// assert.equal(result.rowCount, 0);
// })
// })
assert.equal(result.oid, null);
client.query("INSERT INTO zugzug(name) VALUES('more work?')", assert.calls(function(err, result) {
assert.equal(result.command, "INSERT");
assert.equal(result.rowCount, 1);
process.nextTick(client.end.bind(client));
return false;
}))
}))
}))

View File

@ -22,11 +22,13 @@ var testForTag = function(tagText, callback) {
})
}
var check = function(oid, rowCount, commandType) {
var check = function(oid, rowCount, command) {
return function(result) {
assert.equal(result.oid, oid);
if(oid != null) {
assert.equal(result.oid, oid);
}
assert.equal(result.rowCount, rowCount);
assert.equal(result.commandType, commandType);
assert.equal(result.command, command);
}
}