diff --git a/lib/native/index.js b/lib/native/index.js index f89740db..efb37bfa 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -4,6 +4,7 @@ var EventEmitter = require('events').EventEmitter; var ConnectionParameters = require(__dirname + '/../connection-parameters'); var CopyFromStream = require(__dirname + '/../copystream').CopyFromStream; var CopyToStream = require(__dirname + '/../copystream').CopyToStream; +var JsClient = require(__dirname + '/../client'); // used to import JS escape functions var binding; @@ -80,6 +81,15 @@ Connection.prototype.endCopyFrom = function (msg) { this._endCopyFrom(msg); }; +// use JS version if native version undefined +// happens when PG version < 9.0.0 +if (!Connection.prototype.escapeIdentifier) { + Connection.prototype.escapeIdentifier = JsClient.prototype.escapeIdentifier; +} +if (!Connection.prototype.escapeLiteral) { + Connection.prototype.escapeLiteral = JsClient.prototype.escapeLiteral; +} + Connection.prototype.query = function(config, values, callback) { var query = (config instanceof NativeQuery) ? config : new NativeQuery(config, values, callback); diff --git a/src/binding.cc b/src/binding.cc index 7a2364be..6081171d 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -8,6 +8,9 @@ #define LOG(msg) printf("%s\n",msg); #define TRACE(msg) //printf("%s\n", msg); +#if PG_VERSION_NUM > 90000 +#define ESCAPE_SUPPORTED +#endif #define THROW(msg) return ThrowException(Exception::Error(String::New(msg))); @@ -67,8 +70,10 @@ public: command_symbol = NODE_PSYMBOL("command"); NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect); +#ifdef ESCAPE_SUPPORTED NODE_SET_PROTOTYPE_METHOD(t, "escapeIdentifier", EscapeIdentifier); NODE_SET_PROTOTYPE_METHOD(t, "escapeLiteral", EscapeLiteral); +#endif NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery); NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams); NODE_SET_PROTOTYPE_METHOD(t, "_sendPrepare", SendPrepare); @@ -132,6 +137,7 @@ public: return Undefined(); } +#ifdef ESCAPE_SUPPORTED //v8 entry point into Connection#escapeIdentifier static Handle EscapeIdentifier(const Arguments& args) @@ -183,6 +189,7 @@ public: return scope.Close(jsStr); } +#endif //v8 entry point into Connection#_sendQuery static Handle @@ -361,6 +368,7 @@ protected: return args.This(); } +#ifdef ESCAPE_SUPPORTED char * EscapeIdentifier(const char *str) { TRACE("js::EscapeIdentifier") @@ -372,6 +380,7 @@ protected: TRACE("js::EscapeLiteral") return PQescapeLiteral(connection_, str, strlen(str)); } +#endif int Send(const char *queryText) {