Ticket #16614: support-server-side-cursors.patch
File support-server-side-cursors.patch, 6.7 KB (added by , 13 years ago) |
---|
-
django/db/models/sql/compiler.py
696 696 # are released. 697 697 if self.query.select_for_update and transaction.is_managed(self.using): 698 698 transaction.set_dirty(self.using) 699 for rows in self.execute_sql(MULTI ):699 for rows in self.execute_sql(MULTI, True): 700 700 for row in rows: 701 701 if resolve_columns: 702 702 if fields is None: … … 727 727 728 728 yield row 729 729 730 def execute_sql(self, result_type=MULTI ):730 def execute_sql(self, result_type=MULTI, iterating=False): 731 731 """ 732 732 Run the query against the database and returns the result(s). The 733 733 return value is a single data item if result_type is SINGLE, or an … … 750 750 else: 751 751 return 752 752 753 cursor = self.connection.cursor( )753 cursor = self.connection.cursor(iterating) 754 754 cursor.execute(sql, params) 755 755 756 756 if not result_type: -
django/db/backends/sqlite3/base.py
186 186 self.introspection = DatabaseIntrospection(self) 187 187 self.validation = BaseDatabaseValidation(self) 188 188 189 def _cursor(self ):189 def _cursor(self, iterating=False): 190 190 if self.connection is None: 191 191 settings_dict = self.settings_dict 192 192 if not settings_dict['NAME']: -
django/db/backends/mysql/base.py
303 303 self.connection = None 304 304 return False 305 305 306 def _cursor(self ):306 def _cursor(self, iterating=False): 307 307 if not self._valid_connection(): 308 308 kwargs = { 309 309 'conv': django_conversions, … … 331 331 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 332 332 self.connection.encoders[SafeString] = self.connection.encoders[str] 333 333 connection_created.send(sender=self.__class__, connection=self) 334 cursor = CursorWrapper(self.connection.cursor()) 335 return cursor 334 if iterating: 335 cursor = self.connection.cursor(cursorclass=Database.cursors.SSCursor) 336 else: 337 cursor = self.connection.cursor() 338 return CursorWrapper(cursor) 336 339 337 340 def _rollback(self): 338 341 try: -
django/db/backends/oracle/base.py
452 452 return "%s/%s@%s" % (settings_dict['USER'], 453 453 settings_dict['PASSWORD'], dsn) 454 454 455 def _cursor(self ):455 def _cursor(self, iterating=False): 456 456 cursor = None 457 457 if not self._valid_connection(): 458 458 conn_string = convert_unicode(self._connect_string()) -
django/db/backends/__init__.py
273 273 self.connection.close() 274 274 self.connection = None 275 275 276 def cursor(self ):276 def cursor(self, iterating=False): 277 277 if (self.use_debug_cursor or 278 278 (self.use_debug_cursor is None and settings.DEBUG)): 279 cursor = self.make_debug_cursor(self._cursor( ))279 cursor = self.make_debug_cursor(self._cursor(iterating)) 280 280 else: 281 cursor = util.CursorWrapper(self._cursor( ), self)281 cursor = util.CursorWrapper(self._cursor(iterating), self) 282 282 return cursor 283 283 284 284 def make_debug_cursor(self, cursor): -
django/db/backends/postgresql_psycopg2/base.py
105 105 self.introspection = DatabaseIntrospection(self) 106 106 self.validation = BaseDatabaseValidation(self) 107 107 self._pg_version = None 108 self._cursor_prefix = 'namedcursor' 109 self._cursor_counter = 0 108 110 109 111 def check_constraints(self, table_names=None): 110 112 """ 111 113 To check constraints, we set constraints to immediate. Then, when, we're done we must ensure they 112 114 are returned to deferred. 113 115 """ 114 self.cursor().execute('SET CONSTRAINTS ALL IMMEDIATE') 115 self.cursor().execute('SET CONSTRAINTS ALL DEFERRED') 116 cursor = self.cursor() 117 cursor.execute('SET CONSTRAINTS ALL IMMEDIATE') 118 cursor.execute('SET CONSTRAINTS ALL DEFERRED') 116 119 117 120 def _get_pg_version(self): 118 121 if self._pg_version is None: … … 120 123 return self._pg_version 121 124 pg_version = property(_get_pg_version) 122 125 123 def _cursor(self): 124 new_connection = False 126 def _generate_cursor_name(self): 127 self._cursor_counter += 1 128 return '%s-%d' % (self._cursor_prefix, self._cursor_counter) 129 130 def _cursor(self, iterating=False): 125 131 set_tz = False 126 132 settings_dict = self.settings_dict 127 133 if self.connection is None: 128 new_connection = True129 134 set_tz = settings_dict.get('TIME_ZONE') 130 135 if settings_dict['NAME'] == '': 131 136 from django.core.exceptions import ImproperlyConfigured … … 148 153 self.connection.set_client_encoding('UTF8') 149 154 self.connection.set_isolation_level(self.isolation_level) 150 155 connection_created.send(sender=self.__class__, connection=self) 151 cursor = self.connection.cursor()152 cursor.tzinfo_factory = None153 if new_connection:154 156 if set_tz: 155 cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) 157 # use a throwaway cursor for this SET; if we are creating a 158 # named cursor later this would cause problems otherwise 159 self.connection.cursor().execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) 156 160 self._get_pg_version() 161 if iterating: 162 cursor = self.connection.cursor(name=self._generate_cursor_name()) 163 else: 164 cursor = self.connection.cursor() 165 cursor.tzinfo_factory = None 157 166 return CursorWrapper(cursor) 158 167 159 168 def _enter_transaction_management(self, managed):