mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
parsing the most simplistic error message
This commit is contained in:
parent
61ff6055b7
commit
b4d1c67eb5
13
lib/index.js
13
lib/index.js
@ -3,7 +3,7 @@ var sys = require('sys');
|
||||
var net = require('net');
|
||||
|
||||
var NUL = '\0';
|
||||
var chars = ['R','S','K','Z','Q','C','T','D','X'];
|
||||
var chars = ['R','S','K','Z','Q','C','T','D','X','E'];
|
||||
var charBuff = Buffer(chars.join(''),'utf8');
|
||||
var UTF8 = {};
|
||||
for(var i = 0; i < charBuff.length; i++){
|
||||
@ -154,6 +154,8 @@ p.parseMessage = function() {
|
||||
return this.parseT();
|
||||
case UTF8.D:
|
||||
return this.parseD();
|
||||
case UTF8.E:
|
||||
return this.parseE();
|
||||
default:
|
||||
throw new Error("Unsupported message ID: " + Buffer([messageID]).toString('utf8') + " (" + messageID.toString(16) + ")");
|
||||
}
|
||||
@ -248,6 +250,15 @@ p.parseD = function() {
|
||||
return msg;
|
||||
};
|
||||
|
||||
p.parseE = function() {
|
||||
var msg = this.parseStart('Error');
|
||||
var fieldType = this.readString(1);
|
||||
if(fieldType == '\0') {
|
||||
return msg;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
p.readInt32 = function() {
|
||||
var buffer = this.buffer;
|
||||
return ((buffer[this.offset++] << 24) +
|
||||
|
||||
@ -36,6 +36,7 @@ test('using closed stream', function() {
|
||||
|
||||
test('after stream connects', function() {
|
||||
stream.emit('connect');
|
||||
//TODO - test more of the connection packets
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -192,7 +192,7 @@ test('Client', function() {
|
||||
format: 'text'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
test('parsing rows', function() {
|
||||
@ -222,6 +222,12 @@ test('Client', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('error messages', function() {
|
||||
testForMessage(buffers.error(),{
|
||||
name: 'Error'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -65,7 +65,16 @@ buffers.dataRow = function(columns) {
|
||||
return buf.join(true, 'D');
|
||||
};
|
||||
|
||||
|
||||
buffers.error = function(fields) {
|
||||
fields = fields || [];
|
||||
var buf = new BufferList();
|
||||
fields.forEach(function(field) {
|
||||
buf.addChar(field.type);
|
||||
buf.addCString(field.value);
|
||||
});
|
||||
buf.add(Buffer([0]));//terminator
|
||||
return buf.join(true, 'E');
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user