From 3594ab5185d4bb700c59ad0781f8f56969912436 Mon Sep 17 00:00:00 2001 From: brianc Date: Mon, 28 Feb 2011 22:57:29 -0600 Subject: [PATCH] quick support for integer parameters --- lib/native.js | 9 +++++++ test/native/evented-api-tests.js | 44 +++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/native.js b/lib/native.js index 92614dd..32e05bc 100644 --- a/lib/native.js +++ b/lib/native.js @@ -122,11 +122,20 @@ var NativeQuery = function(text, values) { this.values = values; } EventEmitter.call(this); + this._translateValues(); }; sys.inherits(NativeQuery, EventEmitter); var p = NativeQuery.prototype; +//translates values into strings +p._translateValues = function() { + if(this.values) { + this.values = this.values.map(function(val) { + return val.toString(); + }); + } +} module.exports = { Client: ctor, diff --git a/test/native/evented-api-tests.js b/test/native/evented-api-tests.js index a4af6f2..2cd3cc3 100644 --- a/test/native/evented-api-tests.js +++ b/test/native/evented-api-tests.js @@ -1,6 +1,16 @@ var helper = require(__dirname + "/../test-helper"); var Client = require(__dirname + "/../../lib/native").Client; var conString = helper.connectionString(); + +var setupClient = function() { + var client = new Client(conString); + client.connect(); + client.query("CREATE TEMP TABLE boom(name varchar(10), age integer)"); + client.query("INSERT INTO boom(name, age) VALUES('Aaron', 26)"); + client.query("INSERT INTO boom(name, age) VALUES('Brian', 28)"); + return client; +} + test('connects', function() { var client = new Client(conString); client.connect(); @@ -26,14 +36,6 @@ test('connects', function() { }) }) }) -var setupClient = function() { - var client = new Client(conString); - client.connect(); - client.query("CREATE TEMP TABLE boom(name varchar(10))"); - client.query("INSERT INTO boom(name) VALUES('Aaron')"); - client.query("INSERT INTO boom(name) VALUES('Brian')"); - return client; -} test('multiple results', function() { test('queued queries', function() { @@ -85,5 +87,29 @@ test('parameterized queries', function() { }) }) + test('multiple parameters', function() { + var client = setupClient(); + var q = client.query('SELECT name FROM boom WHERE name = $1 or name = $2 ORDER BY name', ['Aaron', 'Brian']); + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'Aaron'); + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'Brian'); + assert.emits(q, 'end', function() { + client.end(); + }) + }) + }) + }) + + test('integer parameters', function() { + var client = setupClient(); + var q = client.query('SELECT * FROM boom WHERE age > $1', [27]); + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'Brian'); + assert.equal(row.age, 28); + }); + assert.emits(q, 'end', function() { + client.end(); + }) + }) }) -