throw exception when passing non-string to query

This commit is contained in:
brianc 2011-02-24 21:44:03 -06:00
parent cc2ff042ef
commit f4ca716b93
2 changed files with 22 additions and 1 deletions

View File

@ -79,8 +79,11 @@ public:
{
HandleScope scope;
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
String::Utf8Value queryText(args[0]->ToString());
if(!args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("First parameter must be a string query")));
}
String::Utf8Value queryText(args[0]->ToString());
int result = self->Send(*queryText);
if(result == 0) {
THROW("PQsendQuery returned error code");

View File

@ -0,0 +1,18 @@
var helper = require(__dirname + "/../test-helper");
var Client = require(__dirname + "/../../lib/native").Client;
var conString = helper.connectionString();
test('query with non-text as first parameter throws error', function() {
var client = new Client(conString);
client.connect();
assert.emits(client, 'connect', function() {
var err;
try{
client.query({text:{fail: true}});
} catch(e) {
err = e;
}
assert.ok(err != null, "Expected exception to be thrown")
client.end();
})
})