throw exception when passing non-string to query
This commit is contained in:
parent
cc2ff042ef
commit
f4ca716b93
@ -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");
|
||||
|
18
test/native/error-tests.js
Normal file
18
test/native/error-tests.js
Normal 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();
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user