Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _cursor(self):
- new_connection = False
- if not self._valid_connection():
- new_connection = True
- kwargs = {
- 'conv': django_conversions,
- 'charset': 'utf8mb4',
- 'use_unicode': True,
- }
- settings_dict = self.settings_dict
- if settings_dict['USER']:
- kwargs['user'] = settings_dict['USER']
- if settings_dict['NAME']:
- kwargs['db'] = settings_dict['NAME']
- if settings_dict['PASSWORD']:
- kwargs['passwd'] = settings_dict['PASSWORD']
- if settings_dict['HOST'].startswith('/'):
- kwargs['unix_socket'] = settings_dict['HOST']
- elif settings_dict['HOST']:
- kwargs['host'] = settings_dict['HOST']
- if settings_dict['PORT']:
- kwargs['port'] = int(settings_dict['PORT'])
- # We need the number of potentially affected rows after an
- # "UPDATE", not the number of changed rows.
- kwargs['client_flag'] = CLIENT.FOUND_ROWS
- kwargs.update(settings_dict['OPTIONS'])
- self.connection = Database.connect(**kwargs)
- self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
- self.connection.encoders[SafeString] = self.connection.encoders[str]
- self.features.uses_savepoints = \
- self.get_server_version() >= (5, 0, 3)
- connection_created.send(sender=self.__class__, connection=self)
- cursor = self.connection.cursor()
- if new_connection:
- # SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column
- # on a recently-inserted row will return when the field is tested for
- # NULL. Disabling this value brings this aspect of MySQL in line with
- # SQL standards.
- cursor.execute('SET SQL_AUTO_IS_NULL = 0')
- return CursorWrapper(cursor)
Add Comment
Please, Sign In to add comment