Skip to content

Commit 73d09c0

Browse files
committed
Fix compilation on less than postgres 9.0
PQEscapeLiteral was added in 9.0
1 parent a17f44a commit 73d09c0

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

binding.gyp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
'target_defaults': {
3+
'defines': [
4+
'<!@(node ./src/config.js)'
5+
]
6+
},
27
'targets': [
38
{
49
'target_name': 'binding',

src/binding.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class Connection : public ObjectWrap {
137137
EscapeIdentifier(const Arguments& args)
138138
{
139139
HandleScope scope;
140+
#ifdef ESCAPE_NOT_SUPPORTED
141+
THROW("Your version of libpq does not support PQEscapeIdentifier");
142+
#endif
143+
140144
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
141145

142146
char* inputStr = MallocCString(args[0]);
@@ -163,8 +167,13 @@ class Connection : public ObjectWrap {
163167
EscapeLiteral(const Arguments& args)
164168
{
165169
HandleScope scope;
170+
#ifdef ESCAPE_NOT_SUPPORTED
171+
THROW("Your version of libpq does not support PQEscapeLiteral");
172+
#endif
166173
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
167174

175+
176+
168177
char* inputStr = MallocCString(args[0]);
169178

170179
if(!inputStr) {
@@ -364,13 +373,18 @@ class Connection : public ObjectWrap {
364373
char * EscapeIdentifier(const char *str)
365374
{
366375
TRACE("js::EscapeIdentifier")
376+
377+
#ifndef ESCAPE_NOT_SUPPORTED
367378
return PQescapeIdentifier(connection_, str, strlen(str));
379+
#endif
368380
}
369381

370382
char * EscapeLiteral(const char *str)
371383
{
372384
TRACE("js::EscapeLiteral")
385+
#ifndef ESCAPE_NOT_SUPPORTED
373386
return PQescapeLiteral(connection_, str, strlen(str));
387+
#endif
374388
}
375389

376390
int Send(const char *queryText)

src/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var exec = require('child_process').exec;
2+
exec('pg_config --version', function(err, stdout) {
3+
if(err) return err;
4+
var majorVersion = stdout.split(' ')[1].split('.')[0];
5+
if(parseInt(majorVersion) < 9) {
6+
console.log('ESCAPE_NOT_SUPPORTED')
7+
}
8+
});

0 commit comments

Comments
 (0)