mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
parsing ints
This commit is contained in:
parent
c91a65273a
commit
967ec0f6bb
@ -42,7 +42,7 @@ p.connect = function() {
|
||||
});
|
||||
var parser = new Parser();
|
||||
this.stream.on('data', function(buffer) {
|
||||
parser.setBuffer(buffer);
|
||||
parser.setBuffer(buffer);
|
||||
var msg = parser.parseMessage();
|
||||
while(msg) {
|
||||
self.emit('message', msg);
|
||||
@ -80,11 +80,16 @@ p.pulseQueryQueue = function() {
|
||||
this.readyForQuery = false;
|
||||
this.stream.write(query.toBuffer());
|
||||
var rowHandler = function(msg) {
|
||||
query.emit('row',msg.fields)
|
||||
query.processDataRow(msg);
|
||||
};
|
||||
var descriptionHandler = function(fields) {
|
||||
query.processRowDescription(fields);
|
||||
};
|
||||
this.on('rowDescription',descriptionHandler);
|
||||
var endHandler;
|
||||
endHandler = function(msg) {
|
||||
query.emit('end');
|
||||
self.removeListener('rowDescription', descriptionHandler);
|
||||
self.removeListener('commandComplete', endHandler);
|
||||
self.removeListener('dataRow', rowHandler);
|
||||
};
|
||||
|
||||
@ -97,7 +97,7 @@ p.parseField = function() {
|
||||
name: this.parseCString(),
|
||||
tableID: this.parseInt32(),
|
||||
columnID: this.parseInt16(),
|
||||
dataType: this.parseInt32(),
|
||||
dataTypeID: this.parseInt32(),
|
||||
dataTypeSize: this.parseInt16(),
|
||||
dataTypeModifier: this.parseInt32(),
|
||||
format: this.parseInt16() == 0 ? 'text' : 'binary'
|
||||
|
||||
33
lib/query.js
33
lib/query.js
@ -7,7 +7,38 @@ var Query = function() {
|
||||
|
||||
sys.inherits(Query, EventEmitter);
|
||||
|
||||
Query.prototype.toBuffer = function() {
|
||||
var intParser = {
|
||||
fromDbValue: parseInt
|
||||
};
|
||||
|
||||
Query.dataTypes = {
|
||||
20: intParser,
|
||||
21: intParser,
|
||||
23: intParser
|
||||
};
|
||||
|
||||
var p = Query.prototype;
|
||||
|
||||
p.processRowDescription = function(description) {
|
||||
this.fields = description.fields;
|
||||
};
|
||||
|
||||
p.processDataRow = function(dataRow) {
|
||||
var row = dataRow.fields;
|
||||
var fields = this.fields || [];
|
||||
var field, dataType;
|
||||
for(var i = 0, len = row.length; i < len; i++) {
|
||||
field = fields[i] || 0
|
||||
var dataType = Query.dataTypes[field.dataTypeID];
|
||||
if(dataType) {
|
||||
console.log('found data type');
|
||||
row[i] = dataType.fromDbValue(row[i]);
|
||||
}
|
||||
}
|
||||
this.emit('row',row);
|
||||
};
|
||||
|
||||
p.toBuffer = function() {
|
||||
var textBuffer = new Buffer(this.text+'\0','utf8');
|
||||
var len = textBuffer.length + 4;
|
||||
var fullBuffer = new Buffer(len + 1);
|
||||
|
||||
@ -161,7 +161,7 @@ test('Client', function() {
|
||||
name: 'id',
|
||||
tableID: 1,
|
||||
columnID: 2,
|
||||
dataType: 3,
|
||||
dataTypeID: 3,
|
||||
dataTypeSize: 4,
|
||||
dataTypeModifier: 5,
|
||||
format: 'text'
|
||||
@ -179,7 +179,7 @@ test('Client', function() {
|
||||
name: 'bang',
|
||||
tableID: 1,
|
||||
columnID: 2,
|
||||
dataType: 3,
|
||||
dataTypeID: 3,
|
||||
dataTypeSize: 4,
|
||||
dataTypeModifier: 5,
|
||||
format: 'text'
|
||||
@ -190,7 +190,7 @@ test('Client', function() {
|
||||
name: 'whoah',
|
||||
tableID: 10,
|
||||
columnID: 11,
|
||||
dataType: 12,
|
||||
dataTypeID: 12,
|
||||
dataTypeSize: 13,
|
||||
dataTypeModifier: 14,
|
||||
format: 'text'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user