2011-01-27 22:10:45 +08:00
|
|
|
//result object returned from query
|
|
|
|
//in the 'end' event and also
|
|
|
|
//passed as second argument to provided callback
|
|
|
|
var Result = function() {
|
2012-09-10 10:13:36 +08:00
|
|
|
this.command = null;
|
|
|
|
this.rowCount = null;
|
|
|
|
this.oid = null;
|
2011-01-27 22:10:45 +08:00
|
|
|
this.rows = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
var p = Result.prototype;
|
|
|
|
|
|
|
|
var matchRegexp = /([A-Za-z]+) (\d+ )?(\d+)?/
|
|
|
|
|
|
|
|
//adds a command complete message
|
|
|
|
p.addCommandComplete = function(msg) {
|
2012-12-11 13:25:26 +08:00
|
|
|
if(msg.text) {
|
|
|
|
//pure javascript
|
|
|
|
var match = matchRegexp.exec(msg.text);
|
|
|
|
} else {
|
|
|
|
//native bindings
|
|
|
|
var match = matchRegexp.exec(msg.command);
|
|
|
|
}
|
2011-01-27 22:10:45 +08:00
|
|
|
if(match) {
|
|
|
|
this.command = match[1];
|
|
|
|
//match 3 will only be existing on insert commands
|
|
|
|
if(match[3]) {
|
2012-12-11 13:25:26 +08:00
|
|
|
//msg.value is from native bindings
|
|
|
|
this.rowCount = parseInt(match[3] || msg.value);
|
2011-01-27 22:10:45 +08:00
|
|
|
this.oid = parseInt(match[2]);
|
|
|
|
} else {
|
|
|
|
this.rowCount = parseInt(match[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
p.addRow = function(row) {
|
|
|
|
this.rows.push(row);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Result;
|