From e69b6faa82cefea6ca267adaf7ac399e5b2717bc Mon Sep 17 00:00:00 2001 From: brianc Date: Sun, 10 Oct 2010 18:20:24 -0500 Subject: [PATCH] added null terminator (c-string) to query --- lib/index.js | 2 +- test/api-tests.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/index.js b/lib/index.js index 54b56056..0f950dd4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -105,7 +105,7 @@ var Query = function() { sys.inherits(Query, EventEmitter); Query.prototype.toBuffer = function() { - var textBuffer = new Buffer(this.text,'utf8'); + var textBuffer = new Buffer(this.text+'\0','utf8'); var len = textBuffer.length + 4; var fullBuffer = new Buffer(len + 1); fullBuffer[0] = 0x51; diff --git a/test/api-tests.js b/test/api-tests.js index 1238098d..f6f564fb 100644 --- a/test/api-tests.js +++ b/test/api-tests.js @@ -3,10 +3,14 @@ require(__dirname+"/test-helper"); //little helper to make a //fresh client to the test DB var makeClient = function() { - return new Client({ + var client = new Client({ user: 'brian', database: 'pgjstest' }); + client.on('Error', function(msg) { + console.log(msg); + }); + return client; }; var client1 = makeClient(); @@ -27,12 +31,13 @@ var client3 = makeClient(); client3.connect(); client3.on('ReadyForQuery', function() { console.log('client3 ready for query'); - var query = client3.query('create temporary table bang (id integer)'); - query.on('end', function() { - client3.disconnect(); - }); }); +var query = client3.query('create temporary table bang (id integer)'); +query.on('end', function() { + client3.disconnect(); +}); + // client.query('create temporary table bang (id integer)'); // client.query('insert into bang(id) VALUES(1)');