Guest User

Django utf8mb4 support hack

a guest
Jun 15th, 2012
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1.     def _cursor(self):
  2.         new_connection = False
  3.         if not self._valid_connection():
  4.             new_connection = True
  5.             kwargs = {
  6.                 'conv': django_conversions,
  7.                 'charset': 'utf8mb4',
  8.                 'use_unicode': True,
  9.             }
  10.             settings_dict = self.settings_dict
  11.             if settings_dict['USER']:
  12.                 kwargs['user'] = settings_dict['USER']
  13.             if settings_dict['NAME']:
  14.                 kwargs['db'] = settings_dict['NAME']
  15.             if settings_dict['PASSWORD']:
  16.                 kwargs['passwd'] = settings_dict['PASSWORD']
  17.             if settings_dict['HOST'].startswith('/'):
  18.                 kwargs['unix_socket'] = settings_dict['HOST']
  19.             elif settings_dict['HOST']:
  20.                 kwargs['host'] = settings_dict['HOST']
  21.             if settings_dict['PORT']:
  22.                 kwargs['port'] = int(settings_dict['PORT'])
  23.             # We need the number of potentially affected rows after an
  24.             # "UPDATE", not the number of changed rows.
  25.             kwargs['client_flag'] = CLIENT.FOUND_ROWS
  26.             kwargs.update(settings_dict['OPTIONS'])
  27.             self.connection = Database.connect(**kwargs)
  28.             self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
  29.             self.connection.encoders[SafeString] = self.connection.encoders[str]
  30.             self.features.uses_savepoints = \
  31.                 self.get_server_version() >= (5, 0, 3)
  32.             connection_created.send(sender=self.__class__, connection=self)
  33.         cursor = self.connection.cursor()
  34.         if new_connection:
  35.             # SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column
  36.             # on a recently-inserted row will return when the field is tested for
  37.             # NULL.  Disabling this value brings this aspect of MySQL in line with
  38.             # SQL standards.
  39.             cursor.execute('SET SQL_AUTO_IS_NULL = 0')
  40.         return CursorWrapper(cursor)
Add Comment
Please, Sign In to add comment