Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Connection.prototype._pulseQueryQueue = function(initialConnection) {
this._sendQueryPrepared(query.name, query.values||[], query.singleRowMode);
} else {
this._namedQuery = true;
this._namedQueries[query.name] = true;
this._sendPrepare(query.name, query.text, (query.values||[]).length, query.singleRowMode);
}
} else if(query.values) {
Expand Down Expand Up @@ -200,6 +199,7 @@ var clientBuilder = function(config) {
var q = this._activeQuery;
//a named query finished being prepared
if(this._namedQuery) {
this._namedQueries[q.name] = true;
this._namedQuery = false;
this._sendQueryPrepared(q.name, q.values||[]);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Query.prototype.handleDataRow = function(msg) {
};

Query.prototype.handleCommandComplete = function(msg, con) {
if(this.name) {
con.parsedStatements[this.name] = true;
}
this._result.addCommandComplete(msg);
//need to sync after each command complete of a prepared statement
if(this.isPreparedStatement) {
Expand Down Expand Up @@ -137,9 +140,6 @@ Query.prototype.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?
Expand Down
58 changes: 58 additions & 0 deletions test/integration/gh-issues/600-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var async = require('async');
var helper = require('../test-helper');

var db = helper.client();

function createTableFoo(callback){
db.query("create temp table foo(column1 int, column2 int)", callback);
}

function createTableBar(callback){
db.query("create temp table bar(column1 text, column2 text)", callback);
}

function insertDataFoo(callback){
db.query({
name: 'insertFoo',
text: 'insert into foo values($1,$2)',
values:['one','two']
}, callback );
}

function insertDataBar(callback){
db.query({
name: 'insertBar',
text: 'insert into bar values($1,$2)',
values:['one','two']
}, callback );
}

function startTransaction(callback) {
db.query('BEGIN', callback);
}
function endTransaction(callback) {
db.query('COMMIT', callback);
}

function doTransaction(callback) {
// The transaction runs startTransaction, then all queries, then endTransaction,
// no matter if there has been an error in a query in the middle.
startTransaction(function() {
insertDataFoo(function() {
insertDataBar(function() {
endTransaction( callback );
});
});
});
}

var steps = [
createTableFoo,
createTableBar,
doTransaction,
insertDataBar
]

async.series(steps, assert.success(function() {
db.end()
}))
4 changes: 2 additions & 2 deletions test/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ assert.success = function(callback) {
if(err) {
console.log(err);
}
assert.isNull(err);
assert(!err);
callback(arg);
});
} else if (callback.length === 2) {
return assert.calls(function(err, arg1, arg2) {
if(err) {
console.log(err);
}
assert.isNull(err);
assert(!err);
callback(arg1, arg2);
});
} else {
Expand Down