work on executing query

This commit is contained in:
brianc 2010-09-29 02:46:44 -05:00
parent 7478b74d9a
commit 1ef03e27a9
2 changed files with 28 additions and 4 deletions

View File

@ -3,14 +3,15 @@ var sys = require('sys');
var net = require('net');
var NUL = '\0';
var chars = Buffer('RSKZQC','utf8');
var chars = Buffer('RSKZQCT','utf8');
var UTF8 = {
R: chars[0],
S: chars[1],
K: chars[2],
Z: chars[3],
Q: chars[4],
C: chars[5]
C: chars[5],
T: chars[6]
};
@ -125,6 +126,8 @@ p.parseMessage = function() {
return this.parseZ();
case UTF8.C:
return this.parseC();
case UTF8.T:
return this.parseT();
default:
throw new Error("Unsupported message ID: " + Buffer([messageID]).toString('utf8') + " (" + messageID.toString(16) + ")");
}
@ -183,6 +186,20 @@ p.parseZ = function() {
return msg;
};
p.parseT = function() {
var msg = this.parseStart('RowDescription');
msg.rowCount = this.readInt16();
msg.rows = [];
for(var i = 0; i < msg.rowCount; i++){
msg.rows[i] = this.parseRow();
}
return msg;
};
p.parseRow = function() {
return {}
};
p.readInt32 = function() {
var buffer = this.buffer;
return ((buffer[this.offset++] << 24) +
@ -191,6 +208,10 @@ p.readInt32 = function() {
buffer[this.offset++]);
};
p.readInt16 = function() {
return ((this.buffer[this.offset++] << 8) + (this.buffer[this.offset++] << 0));
};
p.parseLength = function() {
return this.readInt32();
};

View File

@ -22,5 +22,8 @@ assert.equal(client.port, 321);
client.port = 5432;
client.connect();
var query = client.query('create temporary table bang (id integer)');
client.query('create temporary table bang (id integer)');
client.query('insert into bang(id) VALUES(1)');
client.query('select * from bang',function(err, results, fields) {
assert.equal(err, null);
});