MysqlDB Python utf8mb4 support
a guest Jun 15th, 2012 1,045 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- def set_character_set(self, charset):
- """Set the connection character set to charset. The character
- set can only be changed in MySQL-4.1 and newer. If you try
- to change the character set from the current value in an
- older version, NotSupportedError will be raised."""
- if self.character_set_name() != charset:
- super(Connection, self).set_character_set(charset)
- except AttributeError:
- if self._server_version < (4, 1):
- raise NotSupportedError("server is too old to set charset")
- self.query('SET NAMES %s' % charset)
- #Hack so data can be decoded/encoded using python's utf8 since
- # python does not know about mysql utf8mb4
- if charset == 'utf8mb4':
- charset = 'utf8'
- self.string_decoder.charset = charset
- self.unicode_literal.charset = charset
RAW Paste Data