|
13 | 13 | #define ESCAPE_SUPPORTED
|
14 | 14 | #endif
|
15 | 15 |
|
| 16 | +#if PG_VERSION_NUM >= 90200 |
| 17 | +#define SINGLE_ROW_SUPPORTED |
| 18 | +#endif |
| 19 | + |
16 | 20 | #define THROW(msg) return ThrowException(Exception::Error(String::New(msg)));
|
17 | 21 |
|
18 | 22 | using namespace v8;
|
@@ -204,7 +208,9 @@ class Connection : public ObjectWrap {
|
204 | 208 | }
|
205 | 209 |
|
206 | 210 | char* queryText = MallocCString(args[0]);
|
207 |
| - int result = self->Send(queryText); |
| 211 | + bool singleRowMode = (bool)args[1]->Int32Value(); |
| 212 | + |
| 213 | + int result = self->Send(queryText, singleRowMode); |
208 | 214 | free(queryText);
|
209 | 215 | if(result == 0) {
|
210 | 216 | lastErrorMessage = self->GetLastError();
|
@@ -234,7 +240,8 @@ class Connection : public ObjectWrap {
|
234 | 240 | String::Utf8Value queryName(args[0]);
|
235 | 241 | String::Utf8Value queryText(args[1]);
|
236 | 242 | int length = args[2]->Int32Value();
|
237 |
| - self->SendPrepare(*queryName, *queryText, length); |
| 243 | + bool singleRowMode = (bool)args[3]->Int32Value(); |
| 244 | + self->SendPrepare(*queryName, *queryText, length, singleRowMode); |
238 | 245 |
|
239 | 246 | return Undefined();
|
240 | 247 | }
|
@@ -274,12 +281,13 @@ class Connection : public ObjectWrap {
|
274 | 281 | }
|
275 | 282 |
|
276 | 283 | char* queryText = MallocCString(args[0]);
|
| 284 | + bool singleRowMode = (bool)args[2]->Int32Value(); |
277 | 285 |
|
278 | 286 | int result = 0;
|
279 | 287 | if(isPrepared) {
|
280 |
| - result = self->SendPreparedQuery(queryText, len, paramValues); |
| 288 | + result = self->SendPreparedQuery(queryText, len, paramValues, singleRowMode); |
281 | 289 | } else {
|
282 |
| - result = self->SendQueryParams(queryText, len, paramValues); |
| 290 | + result = self->SendQueryParams(queryText, len, paramValues, singleRowMode); |
283 | 291 | }
|
284 | 292 |
|
285 | 293 | free(queryText);
|
@@ -383,33 +391,53 @@ class Connection : public ObjectWrap {
|
383 | 391 | }
|
384 | 392 | #endif
|
385 | 393 |
|
386 |
| - int Send(const char *queryText) |
| 394 | + void enableSingleRowMode(bool enable) |
| 395 | + { |
| 396 | +#ifdef SINGLE_ROW_SUPPORTED |
| 397 | + if(enable == true) { |
| 398 | + int mode = PQsetSingleRowMode(connection_); |
| 399 | + if(mode == 1) { |
| 400 | + TRACE("PQsetSingleRowMode enabled") |
| 401 | + } else { |
| 402 | + TRACE("PQsetSingleRowMode disabled") |
| 403 | + } |
| 404 | + } else { |
| 405 | + TRACE("PQsetSingleRowMode disabled") |
| 406 | + } |
| 407 | +#endif |
| 408 | + } |
| 409 | + |
| 410 | + int Send(const char *queryText, bool singleRowMode) |
387 | 411 | {
|
388 | 412 | TRACE("js::Send")
|
389 | 413 | int rv = PQsendQuery(connection_, queryText);
|
| 414 | + enableSingleRowMode(singleRowMode); |
390 | 415 | StartWrite();
|
391 | 416 | return rv;
|
392 | 417 | }
|
393 | 418 |
|
394 |
| - int SendQueryParams(const char *command, const int nParams, const char * const *paramValues) |
| 419 | + int SendQueryParams(const char *command, const int nParams, const char * const *paramValues, bool singleRowMode) |
395 | 420 | {
|
396 | 421 | TRACE("js::SendQueryParams")
|
397 | 422 | int rv = PQsendQueryParams(connection_, command, nParams, NULL, paramValues, NULL, NULL, 0);
|
| 423 | + enableSingleRowMode(singleRowMode); |
398 | 424 | StartWrite();
|
399 | 425 | return rv;
|
400 | 426 | }
|
401 | 427 |
|
402 |
| - int SendPrepare(const char *name, const char *command, const int nParams) |
| 428 | + int SendPrepare(const char *name, const char *command, const int nParams, bool singleRowMode) |
403 | 429 | {
|
404 | 430 | TRACE("js::SendPrepare")
|
405 | 431 | int rv = PQsendPrepare(connection_, name, command, nParams, NULL);
|
| 432 | + enableSingleRowMode(singleRowMode); |
406 | 433 | StartWrite();
|
407 | 434 | return rv;
|
408 | 435 | }
|
409 | 436 |
|
410 |
| - int SendPreparedQuery(const char *name, int nParams, const char * const *paramValues) |
| 437 | + int SendPreparedQuery(const char *name, int nParams, const char * const *paramValues, bool singleRowMode) |
411 | 438 | {
|
412 | 439 | int rv = PQsendQueryPrepared(connection_, name, nParams, paramValues, NULL, NULL, 0);
|
| 440 | + enableSingleRowMode(singleRowMode); |
413 | 441 | StartWrite();
|
414 | 442 | return rv;
|
415 | 443 | }
|
@@ -631,6 +659,9 @@ class Connection : public ObjectWrap {
|
631 | 659 | ExecStatusType status = PQresultStatus(result);
|
632 | 660 | switch(status) {
|
633 | 661 | case PGRES_TUPLES_OK:
|
| 662 | +#ifdef SINGLE_ROW_SUPPORTED |
| 663 | + case PGRES_SINGLE_TUPLE: |
| 664 | +#endif |
634 | 665 | {
|
635 | 666 | EmitRowDescription(result);
|
636 | 667 | HandleTuplesResult(result);
|
|
0 commit comments