Skip to content

Commit f373a32

Browse files
author
adustman
committed
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.
1 parent a1e2fb7 commit f373a32

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

MySQLdb/MySQLdb/connections.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class object, used to create cursors (keyword only)
116116
dictionary or mapping, contains SSL connection parameters;
117117
see the MySQL documentation for more details
118118
(mysql_ssl_set()). If this is set, and the client does not
119-
support SSL, UnsupportedError will be raised.
119+
support SSL, NotSupportedError will be raised.
120120
121121
local_infile
122122
integer, non-zero enables LOAD LOCAL INFILE; zero disables
@@ -253,13 +253,16 @@ def warning_count(self):
253253
return 0
254254

255255
def set_character_set(self, charset):
256-
"""Set the connection character set to charset."""
257-
try:
258-
super(Connection, self).set_character_set(charset)
259-
except AttributeError:
260-
if self._server_version < (4, 1):
261-
raise UnsupportedError, "server is too old to set charset"
262-
if self.character_set_name() != charset:
256+
"""Set the connection character set to charset. The character
257+
set can only be changed in MySQL-4.1 and newer. If you try
258+
to change the character set from the current value in an
259+
older version, NotSupportedError will be raised."""
260+
if self.character_set_name() != charset:
261+
try:
262+
super(Connection, self).set_character_set(charset)
263+
except AttributeError:
264+
if self._server_version < (4, 1):
265+
raise NotSupportedError, "server is too old to set charset"
263266
self.query('SET NAMES %s' % charset)
264267
self.store_result()
265268
self.string_decoder.charset = charset
@@ -269,7 +272,7 @@ def set_sql_mode(self, sql_mode):
269272
"""Set the connection sql_mode. See MySQL documentation for
270273
legal values."""
271274
if self._server_version < (4, 1):
272-
raise UnsupportedError, "server is too old to set sql_mode"
275+
raise NotSupportedError, "server is too old to set sql_mode"
273276
self.query("SET SESSION sql_mode='%s'" % sql_mode)
274277
self.store_result()
275278

0 commit comments

Comments
 (0)