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