2010-10-28 12:51:08 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
|
|
|
|
|
|
|
var client = helper.client();
|
|
|
|
var con = client.connection;
|
|
|
|
var parseArg = null;
|
2010-10-29 08:09:40 +08:00
|
|
|
con.parse = function(arg) {
|
|
|
|
parseArg = arg;
|
|
|
|
process.nextTick(function() {
|
|
|
|
con.emit('parseComplete');
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var bindArg = null;
|
|
|
|
con.bind = function(arg) {
|
|
|
|
bindArg = arg;
|
2010-10-29 08:09:40 +08:00
|
|
|
process.nextTick(function(){
|
|
|
|
con.emit('bindComplete');
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var executeArg = null;
|
|
|
|
con.execute = function(arg) {
|
|
|
|
executeArg = arg;
|
2010-10-29 08:09:40 +08:00
|
|
|
process.nextTick(function() {
|
|
|
|
con.emit('rowData',{ fields: [] });
|
2011-01-19 13:03:24 +08:00
|
|
|
con.emit('commandComplete', { text: "" });
|
2010-10-29 08:09:40 +08:00
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var describeArg = null;
|
|
|
|
con.describe = function(arg) {
|
|
|
|
describeArg = arg;
|
2010-10-29 08:09:40 +08:00
|
|
|
process.nextTick(function() {
|
|
|
|
con.emit('rowDescription', { fields: [] });
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
};
|
|
|
|
|
2010-10-29 08:09:40 +08:00
|
|
|
var syncCalled = false;
|
|
|
|
con.flush = function() {
|
|
|
|
};
|
2010-10-28 12:51:08 +08:00
|
|
|
con.sync = function() {
|
2010-10-29 08:09:40 +08:00
|
|
|
syncCalled = true;
|
|
|
|
process.nextTick(function() {
|
|
|
|
con.emit('readyForQuery');
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
test('bound command', function() {
|
2010-10-28 13:48:02 +08:00
|
|
|
test('simple, unnamed bound command', function() {
|
2010-10-29 08:09:40 +08:00
|
|
|
assert.ok(client.connection.emit('readyForQuery'));
|
|
|
|
|
2010-10-28 12:51:08 +08:00
|
|
|
var query = client.query({
|
2014-06-17 21:15:14 +08:00
|
|
|
text: 'select * from X where name = $1',
|
2010-10-29 08:09:40 +08:00
|
|
|
values: ['hi']
|
2010-10-28 12:51:08 +08:00
|
|
|
});
|
|
|
|
|
2010-11-01 03:43:10 +08:00
|
|
|
assert.emits(query,'end', function() {
|
2010-10-29 08:09:40 +08:00
|
|
|
test('parse argument', function() {
|
|
|
|
assert.equal(parseArg.name, null);
|
2014-06-17 21:15:14 +08:00
|
|
|
assert.equal(parseArg.text, 'select * from X where name = $1');
|
2010-10-29 08:09:40 +08:00
|
|
|
assert.equal(parseArg.types, null);
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
|
2010-10-29 08:09:40 +08:00
|
|
|
test('bind argument', function() {
|
|
|
|
assert.equal(bindArg.statement, null);
|
|
|
|
assert.equal(bindArg.portal, null);
|
2011-10-11 08:21:06 +08:00
|
|
|
assert.lengthIs(bindArg.values, 1);
|
2010-10-29 08:09:40 +08:00
|
|
|
assert.equal(bindArg.values[0], 'hi')
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
|
2010-10-29 08:09:40 +08:00
|
|
|
test('describe argument', function() {
|
|
|
|
assert.equal(describeArg.type, 'P');
|
|
|
|
assert.equal(describeArg.name, "");
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
|
2010-10-29 08:09:40 +08:00
|
|
|
test('execute argument', function() {
|
|
|
|
assert.equal(executeArg.portal, null);
|
|
|
|
assert.equal(executeArg.rows, null);
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
|
2010-10-29 08:09:40 +08:00
|
|
|
test('sync called', function() {
|
|
|
|
assert.ok(syncCalled);
|
|
|
|
});
|
2010-10-28 12:51:08 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|