#403 Only use native escape functions if PG version >= 9.0.0. Otherwise use the JS functions.
This commit is contained in:
parent
baaacd2a8f
commit
cf07a4f2b4
@ -4,6 +4,7 @@ var EventEmitter = require('events').EventEmitter;
|
|||||||
var ConnectionParameters = require(__dirname + '/../connection-parameters');
|
var ConnectionParameters = require(__dirname + '/../connection-parameters');
|
||||||
var CopyFromStream = require(__dirname + '/../copystream').CopyFromStream;
|
var CopyFromStream = require(__dirname + '/../copystream').CopyFromStream;
|
||||||
var CopyToStream = require(__dirname + '/../copystream').CopyToStream;
|
var CopyToStream = require(__dirname + '/../copystream').CopyToStream;
|
||||||
|
var JsClient = require(__dirname + '/../client'); // used to import JS escape functions
|
||||||
|
|
||||||
var binding;
|
var binding;
|
||||||
|
|
||||||
@ -80,6 +81,15 @@ Connection.prototype.endCopyFrom = function (msg) {
|
|||||||
this._endCopyFrom(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) {
|
Connection.prototype.query = function(config, values, callback) {
|
||||||
var query = (config instanceof NativeQuery) ? config :
|
var query = (config instanceof NativeQuery) ? config :
|
||||||
new NativeQuery(config, values, callback);
|
new NativeQuery(config, values, callback);
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#define LOG(msg) printf("%s\n",msg);
|
#define LOG(msg) printf("%s\n",msg);
|
||||||
#define TRACE(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)));
|
#define THROW(msg) return ThrowException(Exception::Error(String::New(msg)));
|
||||||
|
|
||||||
@ -67,8 +70,10 @@ public:
|
|||||||
command_symbol = NODE_PSYMBOL("command");
|
command_symbol = NODE_PSYMBOL("command");
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
||||||
|
#ifdef ESCAPE_SUPPORTED
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "escapeIdentifier", EscapeIdentifier);
|
NODE_SET_PROTOTYPE_METHOD(t, "escapeIdentifier", EscapeIdentifier);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "escapeLiteral", EscapeLiteral);
|
NODE_SET_PROTOTYPE_METHOD(t, "escapeLiteral", EscapeLiteral);
|
||||||
|
#endif
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendPrepare", SendPrepare);
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendPrepare", SendPrepare);
|
||||||
@ -132,6 +137,7 @@ public:
|
|||||||
return Undefined();
|
return Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ESCAPE_SUPPORTED
|
||||||
//v8 entry point into Connection#escapeIdentifier
|
//v8 entry point into Connection#escapeIdentifier
|
||||||
static Handle<Value>
|
static Handle<Value>
|
||||||
EscapeIdentifier(const Arguments& args)
|
EscapeIdentifier(const Arguments& args)
|
||||||
@ -183,6 +189,7 @@ public:
|
|||||||
|
|
||||||
return scope.Close(jsStr);
|
return scope.Close(jsStr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//v8 entry point into Connection#_sendQuery
|
//v8 entry point into Connection#_sendQuery
|
||||||
static Handle<Value>
|
static Handle<Value>
|
||||||
@ -361,6 +368,7 @@ protected:
|
|||||||
return args.This();
|
return args.This();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ESCAPE_SUPPORTED
|
||||||
char * EscapeIdentifier(const char *str)
|
char * EscapeIdentifier(const char *str)
|
||||||
{
|
{
|
||||||
TRACE("js::EscapeIdentifier")
|
TRACE("js::EscapeIdentifier")
|
||||||
@ -372,6 +380,7 @@ protected:
|
|||||||
TRACE("js::EscapeLiteral")
|
TRACE("js::EscapeLiteral")
|
||||||
return PQescapeLiteral(connection_, str, strlen(str));
|
return PQescapeLiteral(connection_, str, strlen(str));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int Send(const char *queryText)
|
int Send(const char *queryText)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user