@@ -200,10 +200,6 @@ class object, used to create cursors (keyword only)
200200 )
201201
202202 self .encoding = "ascii" # overridden in set_character_set()
203- db = proxy (self )
204-
205- def unicode_literal (u , dummy = None ):
206- return db .string_literal (u .encode (db .encoding ))
207203
208204 if not charset :
209205 charset = self .character_set_name ()
@@ -227,7 +223,13 @@ def unicode_literal(u, dummy=None):
227223 # MySQL may return JSON with charset==binary.
228224 self .converter [FIELD_TYPE .JSON ] = str
229225
226+ db = proxy (self )
227+
228+ def unicode_literal (u , dummy = None ):
229+ return db .string_literal (u .encode (db .encoding ))
230+
230231 self .encoders [str ] = unicode_literal
232+
231233 self ._transactional = self .server_capabilities & CLIENT .TRANSACTIONS
232234 if self ._transactional :
233235 if autocommit is not None :
@@ -300,32 +302,10 @@ def begin(self):
300302 """
301303 self .query (b"BEGIN" )
302304
303- if not hasattr (_mysql .connection , "warning_count" ):
304-
305- def warning_count (self ):
306- """Return the number of warnings generated from the
307- last query. This is derived from the info() method."""
308- info = self .info ()
309- if info :
310- return int (info .split ()[- 1 ])
311- else :
312- return 0
313-
314305 def set_character_set (self , charset ):
315- """Set the connection character set to charset. The character
316- set can only be changed in MySQL-4.1 and newer. If you try
317- to change the character set from the current value in an
318- older version, NotSupportedError will be raised."""
319- py_charset = _charset_to_encoding .get (charset , charset )
320- if self .character_set_name () != charset :
321- try :
322- super ().set_character_set (charset )
323- except AttributeError :
324- if self ._server_version < (4 , 1 ):
325- raise NotSupportedError ("server is too old to set charset" )
326- self .query ("SET NAMES %s" % charset )
327- self .store_result ()
328- self .encoding = py_charset
306+ """Set the connection character set to charset."""
307+ super ().set_character_set (charset )
308+ self .encoding = _charset_to_encoding .get (charset , charset )
329309
330310 def set_sql_mode (self , sql_mode ):
331311 """Set the connection sql_mode. See MySQL documentation for
0 commit comments