From 730b3c4ccfa3af33d1258536577cc1d05c3257a8 Mon Sep 17 00:00:00 2001 From: paulc Date: Sun, 22 Mar 2009 21:35:13 +0000 Subject: [PATCH] Added setting for client_encoding of the PostgreSQL connection. git-svn-id: http://voip.null.ro/svn/yate@2530 acf43c95-373e-0410-b603-e72c3f656dc1 --- conf.d/pgsqldb.conf.sample | 4 ++++ modules/server/pgsqldb.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/conf.d/pgsqldb.conf.sample b/conf.d/pgsqldb.conf.sample index 7030a876..33451935 100644 --- a/conf.d/pgsqldb.conf.sample +++ b/conf.d/pgsqldb.conf.sample @@ -16,6 +16,10 @@ ; retry: int: How many times to retry the connection or query ;retry=5 +; encoding: string: Character set encoding used to communicate with the server +; If not set will match the encoding of server side database +;encoding= + ; connection: string: Ready-built client connection string for PQconnectStart ; If this is not set the string is built from the following pieces ; Take care if you set this - it will override anything that follows diff --git a/modules/server/pgsqldb.cpp b/modules/server/pgsqldb.cpp index 2cb010b3..ff405ee6 100644 --- a/modules/server/pgsqldb.cpp +++ b/modules/server/pgsqldb.cpp @@ -56,6 +56,7 @@ private: bool startDb(); int queryDbInternal(const char* query, Message* dest); String m_name,m_connection; + String m_encoding; int m_retry; u_int64_t m_timeout; PGconn *m_conn; @@ -107,6 +108,7 @@ DbConn::DbConn(const NamedList* sect) if (m_timeout < 500000) m_timeout = 500000; m_retry = sect->getIntValue("retry",5); + m_encoding = sect->getValue("encoding"); } DbConn::~DbConn() @@ -139,6 +141,9 @@ bool DbConn::initDb(int retry) return false; case CONNECTION_OK: Debug(&module,DebugAll,"Connection for '%s' succeeded",m_name.c_str()); + if (m_encoding && PQsetClientEncoding(m_conn,m_encoding)) + Debug(&module,DebugWarn,"Failed to set encoding '%s' on connection '%s'", + m_encoding.c_str(),m_name.c_str()); return true; default: break;