Advertisement
Guest User

utf8mb4 mysql hack

a guest
Jun 14th, 2012
1,555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  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."""
  6.                
  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()
  17.        
  18.         self.string_decoder.charset = charset
  19.         self.unicode_literal.charset = charset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement