From 796b8dfadc0bebb781e6722c179cbaee214149b5 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 14 Feb 2011 16:42:04 +0100 Subject: [PATCH] added option for using the binary format --- lib/connection.js | 11 +++++++++-- lib/query.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index b4198bf..2b5c013 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -122,6 +122,7 @@ p.bind = function(config) { config = config || {}; config.portal = config.portal || ''; config.statement = config.statement || ''; + config.binary = config.binary || false; var values = config.values || []; var len = values.length; var buffer = this.writer @@ -139,8 +140,14 @@ p.bind = function(config) { buffer.addString(val); } } - buffer.addInt16(1); // format codes to use binary - buffer.addInt16(1); + + if (config.binary) { + buffer.addInt16(1); // format codes to use binary + buffer.addInt16(1); + } + else { + buffer.addInt16(0); // format codes to use text + } //0x42 = 'B' this._send(0x42, buffer); diff --git a/lib/query.js b/lib/query.js index ecd1885..5747ad3 100644 --- a/lib/query.js +++ b/lib/query.js @@ -10,6 +10,7 @@ var Query = function(config) { this.rows = config.rows; this.types = config.types; this.name = config.name; + this.binary = config.binary; //for code clarity purposes we'll declare this here though it's not //set or used until a rowDescription message comes in this.rowDescription = null; @@ -21,7 +22,7 @@ sys.inherits(Query, EventEmitter); var p = Query.prototype; p.requiresPreparation = function() { - return (this.values || 0).length > 0 || this.name || this.rows; + return (this.values || 0).length > 0 || this.name || this.rows || this.binary; }; @@ -182,7 +183,8 @@ p.prepare = function(connection) { connection.bind({ portal: self.name, statement: self.name, - values: self.values + values: self.values, + binary: self.binary }); connection.describe({