Ticket #6064: 6064-using-signals-3.diff
File 6064-using-signals-3.diff, 6.4 KB (added by , 16 years ago) |
---|
-
django/db/backends/postgresql/base.py
5 5 """ 6 6 7 7 from django.db.backends import * 8 from django.db.backends.signals import connection_created 8 9 from django.db.backends.postgresql.client import DatabaseClient 9 10 from django.db.backends.postgresql.creation import DatabaseCreation 10 11 from django.db.backends.postgresql.introspection import DatabaseIntrospection … … 114 115 conn_string += " port=%s" % settings_dict['DATABASE_PORT'] 115 116 self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS']) 116 117 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 118 connection_created.send(sender=self.__class__) 117 119 cursor = self.connection.cursor() 118 120 if set_tz: 119 121 cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) -
django/db/backends/sqlite3/base.py
8 8 """ 9 9 10 10 from django.db.backends import * 11 from django.db.backends.signals import connection_created 11 12 from django.db.backends.sqlite3.client import DatabaseClient 12 13 from django.db.backends.sqlite3.creation import DatabaseCreation 13 14 from django.db.backends.sqlite3.introspection import DatabaseIntrospection … … 171 172 self.connection.create_function("django_extract", 2, _sqlite_extract) 172 173 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 173 174 self.connection.create_function("regexp", 2, _sqlite_regexp) 175 connection_created.send(sender=self.__class__) 174 176 return self.connection.cursor(factory=SQLiteCursorWrapper) 175 177 176 178 def close(self): -
django/db/backends/mysql/base.py
25 25 from MySQLdb.constants import FIELD_TYPE, FLAG 26 26 27 27 from django.db.backends import * 28 from django.db.backends.signals import connection_created 28 29 from django.db.backends.mysql.client import DatabaseClient 29 30 from django.db.backends.mysql.creation import DatabaseCreation 30 31 from django.db.backends.mysql.introspection import DatabaseIntrospection … … 277 278 self.connection = Database.connect(**kwargs) 278 279 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 279 280 self.connection.encoders[SafeString] = self.connection.encoders[str] 281 connection_created.send(sender=self.__class__) 280 282 cursor = CursorWrapper(self.connection.cursor()) 281 283 return cursor 282 284 -
django/db/backends/oracle/base.py
25 25 raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e) 26 26 27 27 from django.db.backends import * 28 from django.db.backends.signals import connection_created 28 29 from django.db.backends.oracle import query 29 30 from django.db.backends.oracle.client import DatabaseClient 30 31 from django.db.backends.oracle.creation import DatabaseCreation … … 329 330 # Django docs specify cx_Oracle version 4.3.1 or higher, but 330 331 # stmtcachesize is available only in 4.3.2 and up. 331 332 pass 333 connection_created.send(sender=self.__class__) 332 334 if not cursor: 333 335 cursor = FormatStylePlaceholderCursor(self.connection) 334 336 return cursor -
django/db/backends/signals.py
1 from django.dispatch import Signal 2 3 connection_created = Signal() -
django/db/backends/postgresql_psycopg2/base.py
6 6 7 7 from django.conf import settings 8 8 from django.db.backends import * 9 from django.db.backends.signals import connection_created 9 10 from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations 10 11 from django.db.backends.postgresql.client import DatabaseClient 11 12 from django.db.backends.postgresql.creation import DatabaseCreation … … 96 97 conn_params['port'] = settings_dict['DATABASE_PORT'] 97 98 self.connection = Database.connect(**conn_params) 98 99 self.connection.set_client_encoding('UTF8') 100 connection_created.send(sender=self.__class__) 99 101 cursor = self.connection.cursor() 100 102 cursor.tzinfo_factory = None 101 103 if set_tz: -
tests/regressiontests/backends/tests.py
1 1 # -*- coding: utf-8 -*- 2 3 # Unit tests for specific database backends. 4 2 # Unit and doctests for specific database backends. 5 3 import unittest 6 7 4 from django.db import connection 5 from django.db.backends.signals import connection_created 8 6 from django.conf import settings 9 7 10 11 8 class Callproc(unittest.TestCase): 12 9 13 10 def test_dbms_session(self): … … 21 18 else: 22 19 return True 23 20 21 def connection_created_test(sender, **kwargs): 22 print 'connection_created signal' 24 23 24 __test__ = {'API_TESTS': ''} 25 26 # Unfortunately with sqlite3 the in-memory test database cannot be 27 # closed, and so it cannot be re-opened during testing, and so we 28 # sadly disable this test for now. 29 if settings.DATABASE_ENGINE != 'sqlite3': 30 __test__['API_TESTS'] += """ 31 >>> connection_created.connect(connection_created_test) 32 >>> connection.close() # Ensure the connection is closed 33 >>> cursor = connection.cursor() 34 connection_created signal 35 >>> connection_created.disconnect(connection_created_test) 36 >>> cursor = connection.cursor() 37 """ 38 25 39 if __name__ == '__main__': 26 40 unittest.main()