From f762d46c84eb3feaf8bba6ac9b4c4173f4d1483d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 14 Dec 2022 18:26:39 +0200 Subject: [PATCH] pg: add compatibility.h, using a PG_VERSION_NUM check in the preprocessor, to just hardcode the missing CONNECTION_ numbers --- vlib/pg/compatibility.h | 16 ++++++++++++++++ vlib/pg/pg.v | 14 ++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 vlib/pg/compatibility.h diff --git a/vlib/pg/compatibility.h b/vlib/pg/compatibility.h new file mode 100644 index 0000000000..3d82f22111 --- /dev/null +++ b/vlib/pg/compatibility.h @@ -0,0 +1,16 @@ + +#if !defined(PG_VERSION_NUM) +#error VERROR_MESSAGE PG_VERSION_NUM is not defined. Please install the development headers for PostgreSQL, they are usually in a package named libpq-dev +#endif + +#if PG_VERSION_NUM < 100000 + #define CONNECTION_CHECK_WRITABLE 9 +#endif + +#if PG_VERSION_NUM < 100000 + #define CONNECTION_CONSUME 10 +#endif + +#if PG_VERSION_NUM < 120000 + #define CONNECTION_GSS_STARTUP 11 +#endif diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index 3d6a5c6930..a705b905c4 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -13,9 +13,15 @@ import io // PostgreSQL Source Code // https://doxygen.postgresql.org/libpq-fe_8h.html #include + +// for PG_VERSION_NUM, which is defined everywhere at least since PG 9.5 +#include + // for orm #include +#include "@VMODROOT/vlib/pg/compatibility.h" + pub struct DB { mut: conn &C.PGconn = unsafe { nil } @@ -58,10 +64,10 @@ pub enum ConnStatusType { auth_ok = C.CONNECTION_AUTH_OK // Received authentication; waiting for backend startup. setenv = C.CONNECTION_SETENV // Negotiating environment. ssl_startup = C.CONNECTION_SSL_STARTUP // Negotiating SSL. - needed = C.CONNECTION_NEEDED // Internal state: connect() needed - check_writable = C.CONNECTION_CHECK_WRITABLE // Check if we could make a writable connection. - consume = C.CONNECTION_CONSUME // Wait for any pending message and consume them. - // gss_startup = C.CONNECTION_GSS_STARTUP // Negotiating GSSAPI; available since PG 12 + needed = C.CONNECTION_NEEDED // Internal state: connect() needed . Available in PG 8 + check_writable = C.CONNECTION_CHECK_WRITABLE // Check if we could make a writable connection. Available since PG 10 + consume = C.CONNECTION_CONSUME // Wait for any pending message and consume them. Available since PG 10 + gss_startup = C.CONNECTION_GSS_STARTUP // Negotiating GSSAPI; available since PG 12 } [typedef]