From a6ae4130f3e7683c7ce10d9de56e0c8015e6781c Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Fri, 31 Jan 2025 09:34:28 +0200 Subject: [PATCH] [#3731] Remove include "utils/errcodes.h" Effectively removes the dependency on the server-side PostgreSQL library. --- src/lib/pgsql/pgsql_connection.cc | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/lib/pgsql/pgsql_connection.cc b/src/lib/pgsql/pgsql_connection.cc index ea9ab63865..2424b5f999 100644 --- a/src/lib/pgsql/pgsql_connection.cc +++ b/src/lib/pgsql/pgsql_connection.cc @@ -16,25 +16,8 @@ #include #include -#include - -// PostgreSQL errors should be tested based on the SQL state code. Each state -// code is 5 decimal, ASCII, digits, the first two define the category of -// error, the last three are the specific error. PostgreSQL makes the state -// code as a char[5]. Macros for each code are defined in PostgreSQL's -// server/utils/errcodes.h, although they require a second macro, -// MAKE_SQLSTATE for completion. For example, duplicate key error as: -// -// #define ERRCODE_UNIQUE_VIOLATION MAKE_SQLSTATE('2','3','5','0','5') -// -// PostgreSQL deliberately omits the MAKE_SQLSTATE macro so callers can/must -// supply their own. We'll define it as an initialization list: -#define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) {ch1,ch2,ch3,ch4,ch5} -// So we can use it like this: const char some_error[] = ERRCODE_xxxx; -#define PGSQL_STATECODE_LEN 5 -#include - #include +#include using namespace isc::asiolink; using namespace isc::data; @@ -50,8 +33,12 @@ std::string PgSqlConnection::KEA_ADMIN_ = KEA_ADMIN; /// @todo: migrate this default timeout to src/bin/dhcpX/simple_parserX.cc const int PGSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds -const char PgSqlConnection::DUPLICATE_KEY[] = ERRCODE_UNIQUE_VIOLATION; -const char PgSqlConnection::NULL_KEY[] = ERRCODE_NOT_NULL_VIOLATION; +// Length of error codes +constexpr size_t PGSQL_STATECODE_LEN = 5; + +// Error codes from https://www.postgresql.org/docs/current/errcodes-appendix.html or utils/errcodes.h +const char PgSqlConnection::DUPLICATE_KEY[] = "23505"; +const char PgSqlConnection::NULL_KEY[] = "23502"; bool PgSqlConnection::warned_about_tls = false;