diff --git a/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h b/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h index 34220a870..5b6770ccd 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h +++ b/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h @@ -68,6 +68,9 @@ public: void options(mysql_option opt, bool b); /// Set connection options + void options(mysql_option opt, const char* c); + /// Set connection options + void options(mysql_option opt, unsigned int i); /// Set connection options diff --git a/Data/MySQL/src/SessionHandle.cpp b/Data/MySQL/src/SessionHandle.cpp index 900c6b93c..c87e3a8e8 100644 --- a/Data/MySQL/src/SessionHandle.cpp +++ b/Data/MySQL/src/SessionHandle.cpp @@ -81,6 +81,14 @@ void SessionHandle::options(mysql_option opt, bool b) throw ConnectionException("mysql_options error", _pHandle); } + +void SessionHandle::options(mysql_option opt, const char* c) +{ + if (mysql_options(_pHandle, opt, c) != 0) + throw ConnectionException("mysql_options error", _pHandle); +} + + void SessionHandle::options(mysql_option opt, unsigned int i) { #if (POCO_MYSQL_VERSION_NUMBER < 0x050108) diff --git a/Data/MySQL/src/SessionImpl.cpp b/Data/MySQL/src/SessionImpl.cpp index 66514d1e4..ed0bc08d4 100644 --- a/Data/MySQL/src/SessionImpl.cpp +++ b/Data/MySQL/src/SessionImpl.cpp @@ -108,6 +108,7 @@ void SessionImpl::open(const std::string& connect) options["compress"] = ""; options["auto-reconnect"] = ""; options["secure-auth"] = ""; + options["character-set"] = "utf8"; const std::string& connString = connectionString(); for (std::string::const_iterator start = connString.begin();;) @@ -157,6 +158,9 @@ void SessionImpl::open(const std::string& connect) else if (!options["secure-auth"].empty()) throw MySQLException("create session: specify correct secure-auth option (true or false) or skip it"); + if (!options["character-set"].empty()) + _handle.options(MYSQL_SET_CHARSET_NAME, options["character-set"].c_str()); + // Real connect _handle.connect(options["host"].c_str(), options["user"].c_str(),