@@ -97,6 +97,14 @@ class object, used to create cursors (keyword only)
9797 If supplied, the connection character set will be changed
9898 to this character set.
9999
100+ :param str collation:
101+ If ``charset`` and ``collation`` are both supplied, the
102+ character set and collation for the current connection
103+ will be set.
104+
105+ If omitted, empty string, or None, the default collation
106+ for the ``charset`` is implied.
107+
100108 :param str auth_plugin:
101109 If supplied, the connection default authentication plugin will be
102110 changed to this value. Example values:
@@ -167,6 +175,7 @@ class object, used to create cursors (keyword only)
167175
168176 cursorclass = kwargs2 .pop ("cursorclass" , self .default_cursor )
169177 charset = kwargs2 .get ("charset" , "" )
178+ collation = kwargs2 .pop ("collation" , "" )
170179 use_unicode = kwargs2 .pop ("use_unicode" , True )
171180 sql_mode = kwargs2 .pop ("sql_mode" , "" )
172181 self ._binary_prefix = kwargs2 .pop ("binary_prefix" , False )
@@ -193,7 +202,7 @@ class object, used to create cursors (keyword only)
193202
194203 if not charset :
195204 charset = self .character_set_name ()
196- self .set_character_set (charset )
205+ self .set_character_set (charset , collation )
197206
198207 if sql_mode :
199208 self .set_sql_mode (sql_mode )
@@ -285,10 +294,13 @@ def begin(self):
285294 """
286295 self .query (b"BEGIN" )
287296
288- def set_character_set (self , charset ):
297+ def set_character_set (self , charset , collation = None ):
289298 """Set the connection character set to charset."""
290299 super ().set_character_set (charset )
291300 self .encoding = _charset_to_encoding .get (charset , charset )
301+ if collation :
302+ self .query ("SET NAMES %s COLLATE %s" % (charset , collation ))
303+ self .store_result ()
292304
293305 def set_sql_mode (self , sql_mode ):
294306 """Set the connection sql_mode. See MySQL documentation for
0 commit comments