diff --git a/lib/index.js b/lib/index.js index 054115cc..270e0e26 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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(); }; diff --git a/test/api-tests.js b/test/api-tests.js index 622ee31f..1dd6fbe4 100644 --- a/test/api-tests.js +++ b/test/api-tests.js @@ -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); +});