MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / set_character_set

Method set_character_set

pymysql/connections.py:641–659  ·  view source on GitHub ↗

Set charset (and collation) Send "SET NAMES charset [COLLATE collation]" query. Update Connection.encoding based on charset.

(self, charset, collation=None)

Source from the content-addressed store, hash-verified

639 self.set_character_set(charset)
640
641 def set_character_set(self, charset, collation=None):
642 """
643 Set charset (and collation)
644
645 Send "SET NAMES charset [COLLATE collation]" query.
646 Update Connection.encoding based on charset.
647 """
648 # Make sure charset is supported.
649 encoding = charset_by_name(charset).encoding
650
651 if collation:
652 query = f"SET NAMES {charset} COLLATE {collation}"
653 else:
654 query = f"SET NAMES {charset}"
655 self._execute_command(COMMAND.COM_QUERY, query)
656 self._read_packet()
657 self.charset = charset
658 self.encoding = encoding
659 self.collation = collation
660
661 def connect(self, sock=None):
662 self._closed = False

Callers 3

set_charsetMethod · 0.95
connectMethod · 0.95

Calls 2

_execute_commandMethod · 0.95
_read_packetMethod · 0.95

Tested by 1