Ticket #6064: 6064-using-signals-2.diff
File 6064-using-signals-2.diff, 6.1 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 … … 113 114 conn_string += " port=%s" % settings.DATABASE_PORT 114 115 self.connection = Database.connect(conn_string, **self.options) 115 116 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 117 connection_created.send(sender=self.__class__) 116 118 cursor = self.connection.cursor() 117 119 if set_tz: 118 120 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) -
django/db/backends/sqlite3/base.py
7 7 """ 8 8 9 9 from django.db.backends import * 10 from django.db.backends.signals import connection_created 10 11 from django.db.backends.sqlite3.client import DatabaseClient 11 12 from django.db.backends.sqlite3.creation import DatabaseCreation 12 13 from django.db.backends.sqlite3.introspection import DatabaseIntrospection … … 147 148 self.connection.create_function("django_extract", 2, _sqlite_extract) 148 149 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 149 150 self.connection.create_function("regexp", 2, _sqlite_regexp) 151 connection_created.send(sender=self.__class__) 150 152 return self.connection.cursor(factory=SQLiteCursorWrapper) 151 153 152 154 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 … … 262 263 self.connection = Database.connect(**kwargs) 263 264 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 264 265 self.connection.encoders[SafeString] = self.connection.encoders[str] 266 connection_created.send(sender=self.__class__) 265 267 cursor = CursorWrapper(self.connection.cursor()) 266 268 return cursor 267 269 -
django/db/backends/oracle/base.py
17 17 raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e) 18 18 19 19 from django.db.backends import * 20 from django.db.backends.signals import connection_created 20 21 from django.db.backends.oracle import query 21 22 from django.db.backends.oracle.client import DatabaseClient 22 23 from django.db.backends.oracle.creation import DatabaseCreation … … 274 275 # Django docs specify cx_Oracle version 4.3.1 or higher, but 275 276 # stmtcachesize is available only in 4.3.2 and up. 276 277 pass 278 connection_created.send(sender=self.__class__) 277 279 if not cursor: 278 280 cursor = FormatStylePlaceholderCursor(self.connection) 279 281 # Default arraysize of 1 is highly sub-optimal. -
django/db/backends/signals.py
1 from django.dispatch import Signal 2 3 connection_created = Signal() -
django/db/backends/postgresql_psycopg2/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.operations import DatabaseOperations as PostgresqlDatabaseOperations 9 10 from django.db.backends.postgresql.client import DatabaseClient 10 11 from django.db.backends.postgresql.creation import DatabaseCreation … … 84 85 self.connection = Database.connect(conn_string, **self.options) 85 86 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 86 87 self.connection.set_client_encoding('UTF8') 88 connection_created.send(sender=self.__class__) 87 89 cursor = self.connection.cursor() 88 90 cursor.tzinfo_factory = None 89 91 if set_tz: -
tests/regressiontests/backends/tests.py
1 from django.db import connection 2 from django.db.backends.signals import connection_created 3 from django.conf import settings 4 5 def connection_created_test(sender, **kwargs): 6 print 'connection_created signal' 7 8 __test__ = {'API_TESTS': ''} 9 10 # Unfortunately with sqlite3 the in-memory test database cannot be 11 # closed, and so it cannot be re-opened during testing, and so we 12 # sadly disable this test for now. 13 if settings.DATABASE_ENGINE != 'sqlite3': 14 __test__['API_TESTS'] += """ 15 >>> connection_created.connect(connection_created_test) 16 >>> connection.close() # Ensure the connection is closed 17 >>> cursor = connection.cursor() 18 connection_created signal 19 >>> connection_created.disconnect(connection_created_test) 20 >>> cursor = connection.cursor() 21 """