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

Method set_character_set

pymysql/connections.py:643–661  ·  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

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