[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pq 2f63308225 24/63: Use PQexec instead of PQexecParams
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pq 2f63308225 24/63: Use PQexec instead of PQexecParams when no parameters are specified. |
Date: |
Mon, 14 Feb 2022 23:24:22 -0500 (EST) |
branch: externals/pq
commit 2f633082251a3cd3a2da700971de059b60a476eb
Author: Andreas Seltenreich <seltenreich@gmx.de>
Commit: Andreas Seltenreich <seltenreich@gmx.de>
Use PQexec instead of PQexecParams when no parameters are specified.
The former allows multiple statements in the command string.
---
pq.c | 23 +++++++++++++++--------
test.el | 5 ++++-
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/pq.c b/pq.c
index 17f67a9e3b..bb55643ddd 100644
--- a/pq.c
+++ b/pq.c
@@ -137,23 +137,30 @@ Fpq_query (emacs_env *env, ptrdiff_t nargs, emacs_value
args[], void *data)
PGconn *conn = env->get_user_ptr(env, args[0]);
int nParams = nargs - 2;
- const char *paramValues[nParams];
-
- for (int i=0; i<nParams; i++)
- paramValues[i] = my_string_to_c(env, args[2+i]);
char *command = my_string_to_c(env, args[1]);
PQnoticeReceiver old_notice_rx =
PQsetNoticeReceiver(conn, pq_notice_rx, env);
- PGresult *res = PQexecParams(conn, command, nParams,
- NULL, paramValues, NULL, NULL, 0);
+ PGresult *res;
+
+ if (nParams) {
+ const char *paramValues[nParams];
+
+ for (int i=0; i<nParams; i++)
+ paramValues[i] = my_string_to_c(env, args[2+i]);
+
+ res = PQexecParams(conn, command, nParams,
+ NULL, paramValues, NULL, NULL, 0);
+
+ for (int i=0; i<nParams; i++)
+ free((void *)paramValues[i]);
+ } else
+ res = PQexec(conn, command);
PQsetNoticeReceiver(conn, old_notice_rx, NULL);
- for (int i=0; i<nParams; i++)
- free((void *)paramValues[i]);
free(command);
diff --git a/test.el b/test.el
index 76cfb730aa..91327e7c74 100644
--- a/test.el
+++ b/test.el
@@ -3,7 +3,7 @@
(require 'pq)
-(setq con (pq:connectdb "port=5433 dbname=smith"))
+(setq con (pq:connectdb "port=5432 dbname=smith"))
(pq:query con "select version()")
;; ("PostgreSQL 9.4.8 on i686-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10)
4.9.2, 32-bit")
(pq:query con "select 1 union select 2")
@@ -23,6 +23,9 @@
;; provoke a warning
(pq:query con "drop table if exists nonexisting_table")
+;; Multiple statements
+(pq:query con "select 1; select 2; select 3;")
+
(setq con (pq:connectdb))
(setq con nil)
(garbage-collect)
- [elpa] externals/pq 8cbe2e24fc 36/63: Make test notice-receiver more robust., (continued)
- [elpa] externals/pq 8cbe2e24fc 36/63: Make test notice-receiver more robust., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 5fcaa751f2 13/63: Cleanup prototype definitions., ELPA Syncer, 2022/02/14
- [elpa] externals/pq d6e3746c80 40/63: Skip encoding test unless supported by server., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 69d6fba048 06/63: Make argument to pq:connectdb optional., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 37e21db4c2 41/63: Shuffle tests, make gc test emit more info on failure., ELPA Syncer, 2022/02/14
- [elpa] externals/pq cdc04b0b61 27/63: Add missing PQclear calls, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 6f6d8728e5 38/63: Test expected error on invalid encoding., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 527e544165 46/63: Improve error handling on connection failure., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 7a15153e8d 58/63: Protect against NULL SQLSTATE., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 966a05ef25 07/63: Initialize client_encoding to utf8., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 2f63308225 24/63: Use PQexec instead of PQexecParams when no parameters are specified.,
ELPA Syncer <=
- [elpa] externals/pq a70d1fe40d 37/63: Test encoding by using some high unicode codepoints., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 795260553a 17/63: Use load-path in test.el, ELPA Syncer, 2022/02/14
- [elpa] externals/pq a03d2c2e9b 44/63: Update README, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 12c54fbf15 14/63: Add undef DEFUN macro, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 862bf023c0 20/63: Add processing for asynchronous notices., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 9e719959b3 12/63: Avoid global variable for pq:error symbol., ELPA Syncer, 2022/02/14
- [elpa] externals/pq ca337173dd 08/63: Explicitly free the libpq result., ELPA Syncer, 2022/02/14
- [elpa] externals/pq e1d1b77b88 34/63: test: Notice receiver., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 499dc3b50e 57/63: Re-introduce custom error signal pq:error with SQLSTATE., ELPA Syncer, 2022/02/14
- [elpa] externals/pq d738d21b6a 52/63: Add checks for non-local exit., ELPA Syncer, 2022/02/14