Set charset (and collation) Send "SET NAMES charset [COLLATE collation]" query. Update Connection.encoding based on charset.
(self, charset, collation=None)
| 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 |