2010-10-07 10:34:38 +08:00
|
|
|
require(__dirname+'/test-helper');
|
2010-10-24 01:50:59 +08:00
|
|
|
//http://developer.postgresql.org/pgdocs/postgres/protocol-message-formats.html
|
2010-10-07 10:34:38 +08:00
|
|
|
|
|
|
|
var buffers = {};
|
2010-10-07 10:39:52 +08:00
|
|
|
buffers.readyForQuery = function() {
|
|
|
|
return new BufferList()
|
|
|
|
.add(Buffer('I'))
|
|
|
|
.join(true,'Z');
|
|
|
|
};
|
|
|
|
|
|
|
|
buffers.authenticationOk = function() {
|
|
|
|
return new BufferList()
|
2010-10-20 11:55:26 +08:00
|
|
|
.addInt32(0)
|
2010-10-07 10:39:52 +08:00
|
|
|
.join(true, 'R');
|
|
|
|
};
|
|
|
|
|
2010-10-24 07:52:01 +08:00
|
|
|
buffers.authenticationCleartextPassword = function() {
|
|
|
|
return new BufferList()
|
|
|
|
.addInt32(3)
|
|
|
|
.join(true, 'R');
|
|
|
|
};
|
|
|
|
|
|
|
|
buffers.authenticationMD5Password = function() {
|
|
|
|
return new BufferList()
|
|
|
|
.addInt32(5)
|
|
|
|
.add(Buffer([1,2,3,4]))
|
|
|
|
.join(true, 'R');
|
|
|
|
};
|
|
|
|
|
2010-10-07 10:39:52 +08:00
|
|
|
buffers.parameterStatus = function(name, value) {
|
|
|
|
return new BufferList()
|
|
|
|
.addCString(name)
|
|
|
|
.addCString(value)
|
|
|
|
.join(true, 'S');
|
2010-10-09 12:10:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
buffers.backendKeyData = function(processID, secretKey) {
|
|
|
|
return new BufferList()
|
|
|
|
.addInt32(processID)
|
|
|
|
.addInt32(secretKey)
|
|
|
|
.join(true, 'K');
|
|
|
|
};
|
|
|
|
|
|
|
|
buffers.commandComplete = function(string) {
|
|
|
|
return new BufferList()
|
|
|
|
.addCString(string)
|
|
|
|
.join(true, 'C');
|
|
|
|
};
|
2010-10-07 10:39:52 +08:00
|
|
|
|
2010-10-09 12:10:13 +08:00
|
|
|
buffers.rowDescription = function(fields) {
|
|
|
|
fields = fields || [];
|
|
|
|
var buf = new BufferList();
|
|
|
|
buf.addInt16(fields.length);
|
|
|
|
fields.forEach(function(field) {
|
|
|
|
buf.addCString(field.name)
|
|
|
|
.addInt32(field.tableID || 0)
|
|
|
|
.addInt16(field.attributeNumber || 0)
|
|
|
|
.addInt32(field.dataTypeID || 0)
|
|
|
|
.addInt16(field.dataTypeSize || 0)
|
|
|
|
.addInt32(field.typeModifier || 0)
|
|
|
|
.addInt16(field.formatCode || 0)
|
|
|
|
});
|
|
|
|
return buf.join(true, 'T');
|
2010-10-07 10:39:52 +08:00
|
|
|
};
|
2010-10-07 10:34:38 +08:00
|
|
|
|
2010-10-09 12:10:13 +08:00
|
|
|
buffers.dataRow = function(columns) {
|
|
|
|
columns = columns || [];
|
|
|
|
var buf = new BufferList();
|
|
|
|
buf.addInt16(columns.length);
|
|
|
|
columns.forEach(function(col) {
|
|
|
|
if(col == null) {
|
2010-10-11 12:35:59 +08:00
|
|
|
buf.addInt32(-1);
|
2010-10-09 12:10:13 +08:00
|
|
|
} else {
|
|
|
|
var strBuf = new Buffer(col, 'utf8');
|
|
|
|
buf.addInt32(strBuf.length);
|
|
|
|
buf.add(strBuf);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return buf.join(true, 'D');
|
|
|
|
};
|
|
|
|
|
2010-10-11 06:48:27 +08:00
|
|
|
buffers.error = function(fields) {
|
2010-10-25 03:43:25 +08:00
|
|
|
return errorOrNotice(fields).join(true, 'E');
|
|
|
|
};
|
|
|
|
|
|
|
|
buffers.notice = function(fields) {
|
|
|
|
return errorOrNotice(fields).join(true, 'N');
|
|
|
|
};
|
|
|
|
|
|
|
|
var errorOrNotice = function(fields) {
|
2010-10-11 06:48:27 +08:00
|
|
|
fields = fields || [];
|
|
|
|
var buf = new BufferList();
|
|
|
|
fields.forEach(function(field) {
|
|
|
|
buf.addChar(field.type);
|
|
|
|
buf.addCString(field.value);
|
|
|
|
});
|
2010-10-25 03:43:25 +08:00
|
|
|
return buf.add(Buffer([0]));//terminator
|
|
|
|
}
|
2010-10-09 12:10:13 +08:00
|
|
|
|
2010-10-24 01:58:40 +08:00
|
|
|
buffers.parseComplete = function() {
|
|
|
|
return new BufferList().join(true, '1');
|
|
|
|
};
|
2010-10-09 12:10:13 +08:00
|
|
|
|
2010-10-24 05:21:11 +08:00
|
|
|
buffers.bindComplete = function() {
|
|
|
|
return new BufferList().join(true, '2');
|
|
|
|
};
|
|
|
|
|
2010-10-25 03:45:07 +08:00
|
|
|
buffers.notification = function(id, channel, payload) {
|
2010-10-24 11:31:43 +08:00
|
|
|
return new BufferList()
|
|
|
|
.addInt32(id)
|
|
|
|
.addCString(channel)
|
2010-10-24 11:45:03 +08:00
|
|
|
.addCString(payload)
|
2010-10-24 11:31:43 +08:00
|
|
|
.join(true, 'A')
|
|
|
|
};
|
|
|
|
|
2010-10-30 09:33:53 +08:00
|
|
|
buffers.emptyQuery = function() {
|
|
|
|
return new BufferList().join(true, 'I');
|
|
|
|
};
|
|
|
|
|
2010-11-15 07:44:36 +08:00
|
|
|
buffers.portalSuspended = function() {
|
|
|
|
return new BufferList().join(true, 's');
|
|
|
|
};
|
|
|
|
|
2010-10-07 10:34:38 +08:00
|
|
|
module.exports = buffers;
|