diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-26 13:40:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-26 13:40:20 +0200 |
commit | 4ea19dd03241a940a4194ac3bdea89bf7cca8f42 (patch) | |
tree | 45b42f0e5adb5f6f676e0f501926c2bceea38c85 | |
parent | ce69b47672cab339994828e0ff5e28b058a517f0 (diff) |
Add support for specifying client character set for MySQL database
-rw-r--r-- | odb/mysql/connection.cxx | 5 | ||||
-rw-r--r-- | odb/mysql/database.cxx | 16 | ||||
-rw-r--r-- | odb/mysql/database.hxx | 13 |
3 files changed, 32 insertions, 2 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index b783f69..f8e88a0 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -32,6 +32,11 @@ namespace odb if (mysql_init (handle_) == 0) throw bad_alloc (); + if (*db_.charset () != '\0') + // Can only fail if we pass an unknown option. + // + mysql_options (handle_, MYSQL_SET_CHARSET_NAME, db_.charset ()); + // Force the CLIENT_FOUND_ROWS flag so that UPDATE returns the // number of found rows, not the number of changed rows. This // is necessary to distinguish between the object-not-persistent diff --git a/odb/mysql/database.cxx b/odb/mysql/database.cxx index d37351f..8ee072c 100644 --- a/odb/mysql/database.cxx +++ b/odb/mysql/database.cxx @@ -30,6 +30,7 @@ namespace odb const char* host, unsigned int port, const char* socket, + const char* charset, unsigned long client_flags, auto_ptr<connection_factory> factory) : user_ (user ? user : ""), @@ -40,6 +41,7 @@ namespace odb port_ (port), socket_str_ (socket ? socket : ""), socket_ (socket ? socket_str_.c_str () : 0), + charset_ (charset == 0 ? "" : charset), client_flags_ (client_flags), factory_ (factory) { @@ -56,6 +58,7 @@ namespace odb const string& host, unsigned int port, const string* socket, + const string& charset, unsigned long client_flags, auto_ptr<connection_factory> factory) : user_ (user), @@ -66,6 +69,7 @@ namespace odb port_ (port), socket_str_ (socket ? *socket : ""), socket_ (socket ? socket_str_.c_str () : 0), + charset_ (charset), client_flags_ (client_flags), factory_ (factory) { @@ -82,6 +86,7 @@ namespace odb const string& host, unsigned int port, const string* socket, + const string& charset, unsigned long client_flags, auto_ptr<connection_factory> factory) : user_ (user), @@ -92,6 +97,7 @@ namespace odb port_ (port), socket_str_ (socket ? *socket : ""), socket_ (socket ? socket_str_.c_str () : 0), + charset_ (charset), client_flags_ (client_flags), factory_ (factory) { @@ -108,6 +114,7 @@ namespace odb const string& host, unsigned int port, const string& socket, + const string& charset, unsigned long client_flags, auto_ptr<connection_factory> factory) : user_ (user), @@ -118,6 +125,7 @@ namespace odb port_ (port), socket_str_ (socket), socket_ (socket_str_.c_str ()), + charset_ (charset), client_flags_ (client_flags), factory_ (factory) { @@ -134,6 +142,7 @@ namespace odb const string& host, unsigned int port, const string& socket, + const string& charset, unsigned long client_flags, auto_ptr<connection_factory> factory) : user_ (user), @@ -144,6 +153,7 @@ namespace odb port_ (port), socket_str_ (socket), socket_ (socket_str_.c_str ()), + charset_ (charset), client_flags_ (client_flags), factory_ (factory) { @@ -157,10 +167,12 @@ namespace odb database (int& argc, char* argv[], bool erase, + const string& charset, unsigned long client_flags, - std::auto_ptr<connection_factory> factory) + auto_ptr<connection_factory> factory) : passwd_ (0), socket_ (0), + charset_ (charset), client_flags_ (client_flags), factory_ (factory) { @@ -203,7 +215,7 @@ namespace odb } void database:: - print_usage (std::ostream& os) + print_usage (ostream& os) { details::options::print_usage (os); } diff --git a/odb/mysql/database.hxx b/odb/mysql/database.hxx index ba4ee80..be9bb58 100644 --- a/odb/mysql/database.hxx +++ b/odb/mysql/database.hxx @@ -42,6 +42,7 @@ namespace odb const char* host = 0, unsigned int port = 0, const char* socket = 0, + const char* charset = 0, unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -52,6 +53,7 @@ namespace odb const std::string& host = "", unsigned int port = 0, const std::string* socket = 0, + const std::string& charset = "", unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -62,6 +64,7 @@ namespace odb const std::string& host = "", unsigned int port = 0, const std::string* socket = 0, + const std::string& charset = "", unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -72,6 +75,7 @@ namespace odb const std::string& host, unsigned int port, const std::string& socket, + const std::string& charset = "", unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -82,6 +86,7 @@ namespace odb const std::string& host, unsigned int port, const std::string& socket, + const std::string& charset = "", unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -105,6 +110,7 @@ namespace odb database (int& argc, char* argv[], bool erase = false, + const std::string& charset = "", unsigned long client_flags = 0, std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> (0)); @@ -150,6 +156,12 @@ namespace odb return socket_; } + const char* + charset () const + { + return charset_.c_str (); + } + unsigned long client_flags () const { @@ -181,6 +193,7 @@ namespace odb unsigned int port_; std::string socket_str_; const char* socket_; + std::string charset_; unsigned long client_flags_; std::auto_ptr<connection_factory> factory_; }; |