diff --git a/lib/native.js b/lib/native.js index 6630f6a..4d7d27e 100644 --- a/lib/native.js +++ b/lib/native.js @@ -65,7 +65,10 @@ p._pulseQueryQueue = function() { return; } this._activeQuery = query; - if(query.values) { + if(query.name) { + this._sendPrepare(query.name, query.text, (query.values||[]).length); + } + else if(query.values) { //call native function this._sendQueryWithParams(query.text, query.values) } else { @@ -109,6 +112,7 @@ var NativeQuery = function(text, values, callback) { if(typeof text == 'object') { this.text = text.text; this.values = text.values; + this.name = text.name; } else { this.text = text; this.callback = callback; @@ -121,9 +125,6 @@ var NativeQuery = function(text, values, callback) { if(this.callback) { this.rows = []; } - if(typeof this.text != 'string') { - throw new Error("No query text") - } //normalize values if(this.values) { for(var i = 0, len = this.values.length; i < len; i++) { diff --git a/src/binding.cc b/src/binding.cc index ac94cf2..140025b 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -75,6 +75,8 @@ public: NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect); NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery); NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams); + NODE_SET_PROTOTYPE_METHOD(t, "_sendPrepare", SendPrepare); + NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryPrepared", SendQueryPrepared); NODE_SET_PROTOTYPE_METHOD(t, "end", End); target->Set(String::NewSymbol("Connection"), t->GetFunction()); @@ -177,6 +179,29 @@ public: return cString; } + //v8 entry point into Connection#_sendPrepare + static Handle + SendPrepare(const Arguments& args) + { + HandleScope scope; + Connection *self = ObjectWrap::Unwrap(args.This()); + String::Utf8Value queryName(args[0]); + String::Utf8Value queryText(args[1]); + + self->SendPrepare(*queryName, *queryText, 0); + + return Undefined(); + } + + static Handle + SendQueryPrepared(const Arguments& args) + { + HandleScope scope; + Connection *self = ObjectWrap::Unwrap(args.This()); + + return Undefined(); + } + //v8 entry point into Connection#end static Handle End(const Arguments& args) @@ -232,6 +257,11 @@ protected: return PQsendQueryParams(connection_, command, nParams, NULL, paramValues, NULL, NULL, 0); } + int SendPrepare(const char *name, const char *command, const int nParams) + { + return PQsendPrepare(connection_, name, command, nParams, NULL); + } + //flushes socket void Flush() { diff --git a/test/integration/client/no-data-tests.js b/test/integration/client/no-data-tests.js index dfac22c..e8fb3c8 100644 --- a/test/integration/client/no-data-tests.js +++ b/test/integration/client/no-data-tests.js @@ -3,8 +3,8 @@ var helper = require(__dirname + '/test-helper'); test("noData message handling", function() { var client = helper.client(); - - client.query({ + + var q = client.query({ name: 'boom', text: 'create temp table boom(id serial, size integer)' }); @@ -13,6 +13,11 @@ test("noData message handling", function() { name: 'insert', text: 'insert into boom(size) values($1)', values: [100] + }, function(err, result) { + if(err) { + console.log(err); + throw err; + } }); client.query({