Reuse correct connection parameters for PostgreSQL failover

If the failover callback doesn't provide the connection string to use,
default to the originally used one instead of using empty connection
string which is almost certainly not what we want.

Note that this requires storing the original connection parameters in
postgresql_session_backend, as we don't have access to the ones stored
in the session object and it seems wrong to add backlinks from the
backend to the session object.

Closes #793.
This commit is contained in:
Vadim Zeitlin
2020-03-05 15:03:39 +01:00
parent 339a5a3a1d
commit 605db30f6c
3 changed files with 8 additions and 3 deletions

View File

@@ -25,6 +25,7 @@
#endif
#include <soci/soci-backend.h>
#include "soci/connection-parameters.h"
#include <libpq-fe.h>
#include <vector>
@@ -395,6 +396,7 @@ struct postgresql_session_backend : details::session_backend
int statementCount_;
bool single_row_mode_;
PGconn * conn_;
connection_parameters connectionParameters_;
};

View File

@@ -123,8 +123,11 @@ details::postgresql_result::check_for_data(char const* errMsg) const
if (retry)
{
connection_parameters parameters;
parameters.set_connect_string(newTarget);
connection_parameters parameters =
sessionBackend_.connectionParameters_;
if (!newTarget.empty())
parameters.set_connect_string(newTarget);
sessionBackend_.clean_up();

View File

@@ -9,7 +9,6 @@
#include "soci/soci-platform.h"
#include "soci/postgresql/soci-postgresql.h"
#include "soci/session.h"
#include "soci/connection-parameters.h"
#include <libpq/libpq-fs.h> // libpq
#include <cctype>
#include <cstdio>
@@ -69,6 +68,7 @@ void postgresql_session_backend::connect(
"Cannot set extra_float_digits parameter");
conn_ = conn;
connectionParameters_ = parameters;
}
postgresql_session_backend::~postgresql_session_backend()