mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Stop setting "extra_float_digits" for PostgreSQL >= 12
This is unnecessary as v12 implemented Ryu algorithm for floating point number formatting which avoids precision loss by default, so don't run an extra query on every connection in both PostgreSQL backend and ODBC backend when using PostgreSQL driver. This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
@@ -171,16 +171,22 @@ void odbc_session_backend::configure_connection()
|
||||
"\" in unrecognizable format.");
|
||||
}
|
||||
|
||||
details::auto_statement<odbc_statement_backend> st(*this);
|
||||
|
||||
std::string const q(major_ver >= 9 ? "SET extra_float_digits = 3"
|
||||
: "SET extra_float_digits = 2");
|
||||
rc = SQLExecDirect(st.hstmt_, sqlchar_cast(q), static_cast<SQLINTEGER>(q.size()));
|
||||
|
||||
if (is_odbc_error(rc))
|
||||
// As explained in src/backends/postgresql/session.cpp, we need to
|
||||
// increase the number of digits used for floating point values to
|
||||
// ensure that all numbers round trip correctly with old PostgreSQL.
|
||||
if (major_ver < 12)
|
||||
{
|
||||
throw odbc_soci_error(SQL_HANDLE_DBC, henv_,
|
||||
"setting extra_float_digits for PostgreSQL");
|
||||
details::auto_statement<odbc_statement_backend> st(*this);
|
||||
|
||||
std::string const q(major_ver >= 9 ? "SET extra_float_digits = 3"
|
||||
: "SET extra_float_digits = 2");
|
||||
rc = SQLExecDirect(st.hstmt_, sqlchar_cast(q), static_cast<SQLINTEGER>(q.size()));
|
||||
|
||||
if (is_odbc_error(rc))
|
||||
{
|
||||
throw odbc_soci_error(SQL_HANDLE_DBC, henv_,
|
||||
"setting extra_float_digits for PostgreSQL");
|
||||
}
|
||||
}
|
||||
|
||||
// This is extracted from pgapifunc.h header from psqlODBC driver.
|
||||
|
||||
@@ -231,15 +231,19 @@ void postgresql_session_backend::connect(
|
||||
PQtrace(conn, traceFile_);
|
||||
}
|
||||
|
||||
// Increase the number of digits used for floating point values to ensure
|
||||
// that the conversions to/from text round trip correctly, which is not the
|
||||
// case with the default value of 0. Use the maximal supported value, which
|
||||
// was 2 until 9.x and is 3 since it.
|
||||
// With older PostgreSQL versions we need to change the extra_float_digits
|
||||
// parameter to ensure that the conversions to/from text round trip
|
||||
// losslessly. This is not necessary since 12.0, which behaves correctly by
|
||||
// default, but for older versions use the maximal supported value, which
|
||||
// was 2 until 9.x and 3 after it.
|
||||
int const version = PQserverVersion(conn);
|
||||
hard_exec(*this, conn,
|
||||
version >= 90000 ? "SET extra_float_digits = 3"
|
||||
: "SET extra_float_digits = 2",
|
||||
"Cannot set extra_float_digits parameter");
|
||||
if (version < 120000)
|
||||
{
|
||||
hard_exec(*this, conn,
|
||||
version >= 90000 ? "SET extra_float_digits = 3"
|
||||
: "SET extra_float_digits = 2",
|
||||
"Cannot set extra_float_digits parameter");
|
||||
}
|
||||
|
||||
conn_ = conn;
|
||||
connectionParameters_ = parameters;
|
||||
|
||||
Reference in New Issue
Block a user