[odb-users] Changing global locale may lead to database connection
error. PostgreSQL
Andrey Paraskevopulo
andrey.psv at gmail.com
Tue Jul 14 06:29:46 EDT 2015
version: libodb-pgsql-2.4.0
Changing global locale may lead to database connection error.
Example:
int _tmain( int argc, _TCHAR* argv[] )
{
std::locale current_locale("");//users locale is Russian_Russia.1251
std::locale::global(current_locale);//change global locale
...
odb::pgsql::database db("user",
"password",
""/*db*/,
"localhost",
5432);
auto conn = db_db->connection();
}
throws an exception:
Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and
accepting
TCP/IP connections on port 5 432?
...
!!! port value is 5 432 (thousands is separated by the ‘ ’, the same port
value is used for PQconnectdb(const char *conninfo))
Explanation:
odb::pgsql::database has the conninfo_(std::string) member.
conninfo_ is initialized with strings with connection parameters. String is
created by the ostringstream.
One of the parameter is the port (unsigned int).
Convertion from the int to string depends on the current global locale
(every new stream is imbued with a copy of it).
Initially, the global locale is the standard C locale.
But if the global locale is changed, than the string port value may be
formatted as not expected.
Possible solution:
libodb-pgsql-2.4.0
For each ostringstream set a stream a default C locale to produce current
locale-independent text.
ostringstream ss;
imbue(std::locale::classic());
…
Andrey Paraskevopulo
More information about the odb-users
mailing list