MCPcopy
hub / github.com/PyMySQL/PyMySQL / set_character_set

Method set_character_set

pymysql/connections.py:644–662  ·  view source on GitHub ↗

Set charaset (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

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