2011-02-25 11:44:03 +08:00
|
|
|
var helper = require(__dirname + "/../test-helper");
|
2011-08-12 09:59:56 +08:00
|
|
|
var Client = require(__dirname + "/../../lib/native");
|
2011-02-25 11:44:03 +08:00
|
|
|
|
|
|
|
test('query with non-text as first parameter throws error', function() {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-02-25 11:44:03 +08:00
|
|
|
client.connect();
|
|
|
|
assert.emits(client, 'connect', function() {
|
|
|
|
client.end();
|
2013-03-29 02:24:33 +08:00
|
|
|
assert.emits(client, 'end', function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
client.query({text:{fail: true}});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-02-25 11:50:17 +08:00
|
|
|
|
|
|
|
test('parameterized query with non-text as first parameter throws error', function() {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-02-25 11:50:17 +08:00
|
|
|
client.connect();
|
|
|
|
assert.emits(client, 'connect', function() {
|
|
|
|
client.end();
|
2013-03-29 02:24:33 +08:00
|
|
|
assert.emits(client, 'end', function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
client.query({
|
|
|
|
text: {fail: true},
|
|
|
|
values: [1, 2]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-02-25 11:50:17 +08:00
|
|
|
|
2011-02-25 12:06:19 +08:00
|
|
|
var connect = function(callback) {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-02-25 12:06:19 +08:00
|
|
|
client.connect();
|
|
|
|
assert.emits(client, 'connect', function() {
|
|
|
|
callback(client);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
test('parameterized query with non-array for second value', function() {
|
|
|
|
test('inline', function() {
|
|
|
|
connect(function(client) {
|
|
|
|
client.end();
|
2013-03-29 02:24:33 +08:00
|
|
|
assert.emits(client, 'end', function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
client.query("SELECT *", "LKSDJF")
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-02-25 12:06:19 +08:00
|
|
|
|
2011-02-25 12:09:36 +08:00
|
|
|
test('config', function() {
|
2011-02-25 12:06:19 +08:00
|
|
|
connect(function(client) {
|
|
|
|
client.end();
|
2013-03-29 02:24:33 +08:00
|
|
|
assert.emits(client, 'end', function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
client.query({
|
|
|
|
text: "SELECT *",
|
|
|
|
values: "ALSDKFJ"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-02-25 12:06:19 +08:00
|
|
|
|
|
|
|
|