cleanup & fix failing tests to allow for green merge of pull #228

This commit is contained in:
brianc 2012-12-10 22:44:58 -06:00
parent 0c487fc078
commit 1c43930ba1
6 changed files with 54 additions and 40 deletions

View File

@ -166,8 +166,9 @@ p.cancel = function(client, query) {
con.cancel(client.processID, client.secretKey); con.cancel(client.processID, client.secretKey);
}); });
} }
else if (client.queryQueue.indexOf(query) != -1) else if (client.queryQueue.indexOf(query) != -1) {
client.queryQueue.splice(client.queryQueue.indexOf(query), 1); client.queryQueue.splice(client.queryQueue.indexOf(query), 1);
}
}; };
p._pulseQueryQueue = function() { p._pulseQueryQueue = function() {

View File

@ -40,7 +40,18 @@ util.inherits(Query, EventEmitter);
var p = Query.prototype; var p = Query.prototype;
p.requiresPreparation = function() { p.requiresPreparation = function() {
return (this.values || 0).length > 0 || this.name || this.rows || this.binary; //named queries must always be prepared
if(this.name) return true;
//always prepare if there are max number of rows expected per
//portal execution
if(this.rows) return true;
//don't prepare empty text queries
if(!this.text) return false;
//binary should be prepared to specify results should be in binary
//unless there are no parameters
if(this.binary && !this.values) return false;
//prepare if there are values
return (this.values || 0).length > 0;
}; };
@ -139,8 +150,10 @@ p.prepare = function(connection) {
name: self.name, name: self.name,
types: self.types types: self.types
}, true); }, true);
if(this.name) {
connection.parsedStatements[this.name] = true; connection.parsedStatements[this.name] = true;
} }
}
//TODO is there some better way to prepare values for the database? //TODO is there some better way to prepare values for the database?
if(self.values) { if(self.values) {

View File

@ -5,7 +5,7 @@ test("cancellation of a query", function() {
var client = helper.client(); var client = helper.client();
var qry = client.query("select name from person order by name"); var qry = "select name from person order by name";
client.on('drain', client.end.bind(client)); client.on('drain', client.end.bind(client));

View File

@ -5,11 +5,11 @@ test("empty query message handling", function() {
assert.emits(client, 'drain', function() { assert.emits(client, 'drain', function() {
client.end(); client.end();
}); });
client.query({text: "", binary: false}); client.query({text: ""});
}); });
test('callback supported', assert.calls(function() { test('callback supported', assert.calls(function() {
client.query({text: "", binary: false}, function(err, result) { client.query("", function(err, result) {
assert.isNull(err); assert.isNull(err);
assert.empty(result.rows); assert.empty(result.rows);
}) })

View File

@ -38,7 +38,7 @@ test("simple query interface", function() {
test("multiple simple queries", function() { test("multiple simple queries", function() {
var client = helper.client(); var client = helper.client();
client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');", binary: false }) client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');"})
client.query("insert into bang(name) VALUES ('yes');"); client.query("insert into bang(name) VALUES ('yes');");
var query = client.query("select name from bang"); var query = client.query("select name from bang");
assert.emits(query, 'row', function(row) { assert.emits(query, 'row', function(row) {
@ -52,9 +52,9 @@ test("multiple simple queries", function() {
test("multiple select statements", function() { test("multiple select statements", function() {
var client = helper.client(); var client = helper.client();
client.query({text: "create temp table boom(age integer); insert into boom(age) values(1); insert into boom(age) values(2); insert into boom(age) values(3)", binary: false}); client.query("create temp table boom(age integer); insert into boom(age) values(1); insert into boom(age) values(2); insert into boom(age) values(3)");
client.query({text: "create temp table bang(name varchar(5)); insert into bang(name) values('zoom');", binary: false}); client.query({text: "create temp table bang(name varchar(5)); insert into bang(name) values('zoom');"});
var result = client.query({text: "select age from boom where age < 2; select name from bang", binary: false}); var result = client.query({text: "select age from boom where age < 2; select name from bang"});
assert.emits(result, 'row', function(row) { assert.emits(result, 'row', function(row) {
assert.strictEqual(row['age'], 1); assert.strictEqual(row['age'], 1);
assert.emits(result, 'row', function(row) { assert.emits(result, 'row', function(row) {

View File

@ -28,7 +28,7 @@ assert.same = function(actual, expected) {
assert.emits = function(item, eventName, callback, message) { assert.emits = function(item, eventName, callback, message) {
var called = false; var called = false;
var id = setTimeout(function() { var id = setTimeout(function() {
test("Should have called " + eventName, function() { test("Should have called '" + eventName + "' event", function() {
assert.ok(called, message || "Expected '" + eventName + "' to be called.") assert.ok(called, message || "Expected '" + eventName + "' to be called.")
}); });
},5000); },5000);