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-27 22:10:45 +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({
|
|
|
|
text: 'select * 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);
|
|
|
|
assert.equal(parseArg.text, 'select * where name = $1');
|
|
|
|
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);
|
|
|
|
assert.length(bindArg.values, 1);
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|