From f373a32f9568372bdf4c24425c9b9ad1db8c3fd6 Mon Sep 17 00:00:00 2001 From: adustman Date: Tue, 4 Apr 2006 15:04:20 +0000 Subject: [PATCH] raise NotSupportedError instead of non-existent UnsupportedError connection.set_character_set() now avoids raising an exception if the current character set is already correct, regardless of MySQL version. --- MySQLdb/MySQLdb/connections.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index 4482a34..77949c7 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -116,7 +116,7 @@ class Connection(_mysql.connection): dictionary or mapping, contains SSL connection parameters; see the MySQL documentation for more details (mysql_ssl_set()). If this is set, and the client does not - support SSL, UnsupportedError will be raised. + support SSL, NotSupportedError will be raised. local_infile integer, non-zero enables LOAD LOCAL INFILE; zero disables @@ -253,13 +253,16 @@ class Connection(_mysql.connection): return 0 def set_character_set(self, charset): - """Set the connection character set to charset.""" - try: - super(Connection, self).set_character_set(charset) - except AttributeError: - if self._server_version < (4, 1): - raise UnsupportedError, "server is too old to set charset" - if self.character_set_name() != charset: + """Set the connection character set to charset. The character + set can only be changed in MySQL-4.1 and newer. If you try + to change the character set from the current value in an + older version, NotSupportedError will be raised.""" + if self.character_set_name() != charset: + try: + super(Connection, self).set_character_set(charset) + except AttributeError: + if self._server_version < (4, 1): + raise NotSupportedError, "server is too old to set charset" self.query('SET NAMES %s' % charset) self.store_result() self.string_decoder.charset = charset @@ -269,7 +272,7 @@ class Connection(_mysql.connection): """Set the connection sql_mode. See MySQL documentation for legal values.""" if self._server_version < (4, 1): - raise UnsupportedError, "server is too old to set sql_mode" + raise NotSupportedError, "server is too old to set sql_mode" self.query("SET SESSION sql_mode='%s'" % sql_mode) self.store_result()