mirror of
https://github.com/brianc/node-postgres.git
synced 2026-02-01 16:47:23 +00:00
can read single data row of text
This commit is contained in:
parent
5cf151ad7a
commit
ab0076aa68
15
lib/index.js
15
lib/index.js
@ -212,7 +212,14 @@ p.parseField = function() {
|
|||||||
|
|
||||||
p.parseD = function() {
|
p.parseD = function() {
|
||||||
var msg = this.parseStart('DataRow');
|
var msg = this.parseStart('DataRow');
|
||||||
msg.fieldCount = this.readInt16();
|
var fieldCount = this.readInt16();
|
||||||
|
var fields = [];
|
||||||
|
for(var i = 0; i < fieldCount; i++) {
|
||||||
|
fields[i] = this.readString(this.readInt32());
|
||||||
|
};
|
||||||
|
msg.fieldCount = fieldCount;
|
||||||
|
msg.fields = fields;
|
||||||
|
return msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
p.readInt32 = function() {
|
p.readInt32 = function() {
|
||||||
@ -231,7 +238,11 @@ p.parseLength = function() {
|
|||||||
return this.readInt32();
|
return this.readInt32();
|
||||||
};
|
};
|
||||||
|
|
||||||
p.parseCString = function(buffer) {
|
p.readString = function(length) {
|
||||||
|
return this.buffer.toString('utf8', this.offset, (this.offset += length));
|
||||||
|
};
|
||||||
|
|
||||||
|
p.parseCString = function() {
|
||||||
var start = this.offset;
|
var start = this.offset;
|
||||||
while(this.buffer[this.offset++]) { };
|
while(this.buffer[this.offset++]) { };
|
||||||
return this.buffer.toString('utf8',start, this.offset - 1);
|
return this.buffer.toString('utf8',start, this.offset - 1);
|
||||||
|
|||||||
@ -184,13 +184,29 @@ test('Parser on single messages', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('parses raw data row buffers', function() {
|
test('parses raw data row buffers', function() {
|
||||||
|
|
||||||
var emptyRow = new BufferList()
|
var emptyRow = new BufferList()
|
||||||
.addInt16(0)
|
.addInt16(0)
|
||||||
.join(true, 'D');
|
.join(true, 'D');
|
||||||
|
|
||||||
test('parses empty data row', function() {
|
test('parses empty data row', function() {
|
||||||
var result = PARSE(emptyRow)[0];
|
var result = PARSE(emptyRow)[0];
|
||||||
assert.equal(result.columnCount, 0);
|
assert.equal(result.fieldCount, 0);
|
||||||
|
assert.equal(result.fields.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var oneField = new BufferList()
|
||||||
|
.addInt16(1) //number of fields
|
||||||
|
.addInt32(5) //length of bytes of fields
|
||||||
|
.addCString('test')
|
||||||
|
.join(true, 'D');
|
||||||
|
|
||||||
|
test('parses single field data row', function() {
|
||||||
|
var result = PARSE(oneField)[0];
|
||||||
|
assert.equal(result.fieldCount, 1);
|
||||||
|
assert.equal(result.fields[0], "test\0");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parsing empty buffer returns false', function() {
|
test('parsing empty buffer returns false', function() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user