mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
support for 'notice' messages
This commit is contained in:
parent
cf211fb1a7
commit
ee4a65b923
@ -186,6 +186,7 @@ var messageNames = {
|
||||
T: 'rowDescription',
|
||||
D: 'dataRow',
|
||||
E: 'error',
|
||||
N: 'notice',
|
||||
1: 'parseComplete',
|
||||
2: 'bindComplete',
|
||||
A: 'notificationResponse'
|
||||
@ -321,6 +322,9 @@ p.parseE = function(msg) {
|
||||
return msg;
|
||||
};
|
||||
|
||||
//same thing, different name
|
||||
p.parseN = p.parseE;
|
||||
|
||||
//parses parseComplete
|
||||
p.parse1 = function(msg) {
|
||||
return msg;
|
||||
|
||||
@ -80,15 +80,22 @@ buffers.dataRow = function(columns) {
|
||||
};
|
||||
|
||||
buffers.error = function(fields) {
|
||||
return errorOrNotice(fields).join(true, 'E');
|
||||
};
|
||||
|
||||
buffers.notice = function(fields) {
|
||||
return errorOrNotice(fields).join(true, 'N');
|
||||
};
|
||||
|
||||
var errorOrNotice = 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');
|
||||
};
|
||||
return buf.add(Buffer([0]));//terminator
|
||||
}
|
||||
|
||||
buffers.parseComplete = function() {
|
||||
return new BufferList().join(true, '1');
|
||||
|
||||
@ -256,6 +256,15 @@ test('Connection', function() {
|
||||
|
||||
});
|
||||
|
||||
test('notice message', function() {
|
||||
//this uses the same logic as error message
|
||||
var buff = buffers.notice([{type: 'C', value: 'code'}]);
|
||||
testForMessage(buff, {
|
||||
name: 'notice',
|
||||
code: 'code'
|
||||
});
|
||||
});
|
||||
|
||||
test('error messages', function() {
|
||||
test('with no fields', function() {
|
||||
var msg = testForMessage(buffers.error(),{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user