cleanup & fix failing tests to allow for green merge of pull #228
This commit is contained in:
parent
0c487fc078
commit
1c43930ba1
@ -166,8 +166,9 @@ p.cancel = function(client, query) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
p._pulseQueryQueue = function() {
|
||||
|
15
lib/query.js
15
lib/query.js
@ -40,7 +40,18 @@ util.inherits(Query, EventEmitter);
|
||||
var p = Query.prototype;
|
||||
|
||||
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,
|
||||
types: self.types
|
||||
}, true);
|
||||
if(this.name) {
|
||||
connection.parsedStatements[this.name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO is there some better way to prepare values for the database?
|
||||
if(self.values) {
|
||||
|
@ -5,7 +5,7 @@ test("cancellation of a query", function() {
|
||||
|
||||
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));
|
||||
|
||||
|
@ -5,11 +5,11 @@ test("empty query message handling", function() {
|
||||
assert.emits(client, 'drain', function() {
|
||||
client.end();
|
||||
});
|
||||
client.query({text: "", binary: false});
|
||||
client.query({text: ""});
|
||||
});
|
||||
|
||||
test('callback supported', assert.calls(function() {
|
||||
client.query({text: "", binary: false}, function(err, result) {
|
||||
client.query("", function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.empty(result.rows);
|
||||
})
|
||||
|
@ -38,7 +38,7 @@ test("simple query interface", function() {
|
||||
|
||||
test("multiple simple queries", function() {
|
||||
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');");
|
||||
var query = client.query("select name from bang");
|
||||
assert.emits(query, 'row', function(row) {
|
||||
@ -52,9 +52,9 @@ test("multiple simple queries", function() {
|
||||
|
||||
test("multiple select statements", function() {
|
||||
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({text: "create temp table bang(name varchar(5)); insert into bang(name) values('zoom');", binary: false});
|
||||
var result = client.query({text: "select age from boom where age < 2; select name from bang", 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');"});
|
||||
var result = client.query({text: "select age from boom where age < 2; select name from bang"});
|
||||
assert.emits(result, 'row', function(row) {
|
||||
assert.strictEqual(row['age'], 1);
|
||||
assert.emits(result, 'row', function(row) {
|
||||
|
@ -28,7 +28,7 @@ assert.same = function(actual, expected) {
|
||||
assert.emits = function(item, eventName, callback, message) {
|
||||
var called = false;
|
||||
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.")
|
||||
});
|
||||
},5000);
|
||||
|
Loading…
Reference in New Issue
Block a user