daily pastebin goal

utf8mb4 mysql hack

a guest Jun 14th, 2012 801 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     def set_character_set(self, charset):        
  2.         """Set the connection character set to charset. The character
  3.        set can only be changed in MySQL-4.1 and newer. If you try
  4.        to change the character set from the current value in an
  5.        older version, NotSupportedError will be raised."""
  7.         if self.character_set_name() != charset:
  8.             try:
  9.                 super(Connection, self).set_character_set(charset)
  10.                 #FIXME: This is a hack
  11.                 self.query('SET NAMES utf8mb4')
  12.             except AttributeError:
  13.                 if self._server_version < (4, 1):
  14.                     raise NotSupportedError("server is too old to set charset")
  15.                 self.query('SET NAMES %s' % charset)
  16.                 self.store_result()
  18.         self.string_decoder.charset = charset
  19.         self.unicode_literal.charset = charset
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand