2012-12-11 16:09 keltezéssel, Simon Riggs írta:
On 11 December 2012 12:18, Boszormenyi Zoltan <z...@cybertec.at> wrote:
Such mechanism already exist - you just need to set
your PGresult pointer to NULL after each PQclear().
So why doesn't PQclear() do that?
Because then PQclear() would need a ** not a *. Do you want its
interface changed for 9.3 and break compatibility with previous versions?
No, but we should introduce a new public API call that is safer,
otherwise we get people continually re-inventing new private APIs that
Do the Right Thing, as the two other respondents have shown.
How about these macros?
Best regards,
Zoltán Böszörményi
--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/
diff -durpN postgresql.3/src/interfaces/libpq/libpq-fe.h postgresql.4/src/interfaces/libpq/libpq-fe.h
--- postgresql.3/src/interfaces/libpq/libpq-fe.h 2013-01-02 09:19:03.929522614 +0100
+++ postgresql.4/src/interfaces/libpq/libpq-fe.h 2013-01-02 16:10:51.978974575 +0100
@@ -256,6 +256,16 @@ extern PGconn *PQsetdbLogin(const char *
/* close the current connection and free the PGconn data structure */
extern void PQfinish(PGconn *conn);
+/* macro to close the current connection and set the conn pointer to NULL */
+#define PQfinishSafe(conn) \
+ { \
+ if (conn) \
+ { \
+ PQfinish(conn); \
+ conn = NULL; \
+ } \
+ }
+
/* get info about connection options known to PQconnectdb */
extern PQconninfoOption *PQconndefaults(void);
@@ -472,6 +482,16 @@ extern int PQsendDescribePortal(PGconn *
/* Delete a PGresult */
extern void PQclear(PGresult *res);
+/* Macro to delete a PGresult and set the res pointer to NULL */
+#define PQclearSafe(res) \
+ { \
+ if (res) \
+ { \
+ PQclear(res); \
+ res = NULL; \
+ } \
+ }
+
/* For freeing other alloc'd results, such as PGnotify structs */
extern void PQfreemem(void *ptr);
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers