def _cursor(self): settings_dict = self.settings_dict if self.connection is None: if settings_dict['NAME'] == '': from django.core.exceptions import ImproperlyConfigured raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") conn_params = { 'database': settings_dict['NAME'], } conn_params.update(settings_dict['OPTIONS']) if 'autocommit' in conn_params: del conn_params['autocommit'] if settings_dict['USER']: conn_params['user'] = settings_dict['USER'] if settings_dict['PASSWORD']: conn_params['password'] = settings_dict['PASSWORD'] if settings_dict['HOST']: conn_params['host'] = settings_dict['HOST'] if settings_dict['PORT']: conn_params['port'] = settings_dict['PORT'] self.connection = self.new_connection() self.connection.set_client_encoding('UTF8') tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE') if tz: try: get_parameter_status = self.connection.get_parameter_status except AttributeError: # psycopg2 < 2.0.12 doesn't have get_parameter_status conn_tz = None else: conn_tz = get_parameter_status('TimeZone') if conn_tz != tz: # Set the time zone in autocommit mode (see #17062) # self.connection.set_isolation_level(PyConnectionEx.ISOLATION_LEVEL_AUTOCOMMIT) self.connection.set_auto_commit(True) self.connection.cursor().execute(self.ops.set_time_zone_sql() % (tz,)) self.connection.set_isolation_level(self.isolation_level) self._get_pg_version() connection_created.send(sender=self.__class__, connection=self) cursor = CursorWrapper(self.connection.cursor()) cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None return cursor
def _cursor(self): new_connection = False if not self._valid_connection(): new_connection = True #self.connection = Database.connect(**kwargs) #removed# self.connection = self.new_connection() #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) # make transactions transparent to all cursors set_default_isolation_level(self.connection, innodb_binlog=True) 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)