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

Method set_character_set

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

651 self.set_character_set(charset)
652
653 def set_character_set(self, charset, collation=None):
654 """
655 Set charset (and collation)
656
657 Send "SET NAMES charset [COLLATE collation]" query.
658 Update Connection.encoding based on charset.
659 """
660 # Make sure charset is supported.
661 encoding = charset_by_name(charset).encoding
662
663 if collation:
664 query = f"SET NAMES {charset} COLLATE {collation}"
665 else:
666 query = f"SET NAMES {charset}"
667 self._execute_command(COMMAND.COM_QUERY, query)
668 self._read_packet()
669 self.charset = charset
670 self.encoding = encoding
671 self.collation = collation
672
673 def connect(self, sock=None):
674 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