1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

pg: add compatibility.h, using a PG_VERSION_NUM check in the preprocessor, to just hardcode the missing CONNECTION_ numbers

This commit is contained in:
Delyan Angelov 2022-12-14 18:26:39 +02:00
parent 34f5255bb5
commit f762d46c84
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 26 additions and 4 deletions

16
vlib/pg/compatibility.h Normal file
View File

@ -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

View File

@ -13,9 +13,15 @@ import io
// PostgreSQL Source Code
// https://doxygen.postgresql.org/libpq-fe_8h.html
#include <libpq-fe.h>
// for PG_VERSION_NUM, which is defined everywhere at least since PG 9.5
#include <pg_config.h>
// for orm
#include <arpa/inet.h>
#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]