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