Ticket #6064: 6064-using-signals-2.diff

File 6064-using-signals-2.diff, 6.1 KB (added by mdh, 16 years ago)

Updated patch to apply against trunk as of r9477.

  • django/db/backends/postgresql/base.py

     
    55"""
    66
    77from django.db.backends import *
     8from django.db.backends.signals import connection_created
    89from django.db.backends.postgresql.client import DatabaseClient
    910from django.db.backends.postgresql.creation import DatabaseCreation
    1011from django.db.backends.postgresql.introspection import DatabaseIntrospection
     
    113114                conn_string += " port=%s" % settings.DATABASE_PORT
    114115            self.connection = Database.connect(conn_string, **self.options)
    115116            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     117            connection_created.send(sender=self.__class__)
    116118        cursor = self.connection.cursor()
    117119        if set_tz:
    118120            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
  • django/db/backends/sqlite3/base.py

     
    77"""
    88
    99from django.db.backends import *
     10from django.db.backends.signals import connection_created
    1011from django.db.backends.sqlite3.client import DatabaseClient
    1112from django.db.backends.sqlite3.creation import DatabaseCreation
    1213from django.db.backends.sqlite3.introspection import DatabaseIntrospection
     
    147148            self.connection.create_function("django_extract", 2, _sqlite_extract)
    148149            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
    149150            self.connection.create_function("regexp", 2, _sqlite_regexp)
     151            connection_created.send(sender=self.__class__)
    150152        return self.connection.cursor(factory=SQLiteCursorWrapper)
    151153
    152154    def close(self):
  • django/db/backends/mysql/base.py

     
    2525from MySQLdb.constants import FIELD_TYPE, FLAG
    2626
    2727from django.db.backends import *
     28from django.db.backends.signals import connection_created
    2829from django.db.backends.mysql.client import DatabaseClient
    2930from django.db.backends.mysql.creation import DatabaseCreation
    3031from django.db.backends.mysql.introspection import DatabaseIntrospection
     
    262263            self.connection = Database.connect(**kwargs)
    263264            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    264265            self.connection.encoders[SafeString] = self.connection.encoders[str]
     266            connection_created.send(sender=self.__class__)
    265267        cursor = CursorWrapper(self.connection.cursor())
    266268        return cursor
    267269
  • django/db/backends/oracle/base.py

     
    1717    raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
    1818
    1919from django.db.backends import *
     20from django.db.backends.signals import connection_created
    2021from django.db.backends.oracle import query
    2122from django.db.backends.oracle.client import DatabaseClient
    2223from django.db.backends.oracle.creation import DatabaseCreation
     
    274275                # Django docs specify cx_Oracle version 4.3.1 or higher, but
    275276                # stmtcachesize is available only in 4.3.2 and up.
    276277                pass
     278            connection_created.send(sender=self.__class__)
    277279        if not cursor:
    278280            cursor = FormatStylePlaceholderCursor(self.connection)
    279281        # Default arraysize of 1 is highly sub-optimal.
  • django/db/backends/signals.py

     
     1from django.dispatch import Signal
     2
     3connection_created = Signal()
  • django/db/backends/postgresql_psycopg2/base.py

     
    55"""
    66
    77from django.db.backends import *
     8from django.db.backends.signals import connection_created
    89from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations
    910from django.db.backends.postgresql.client import DatabaseClient
    1011from django.db.backends.postgresql.creation import DatabaseCreation
     
    8485            self.connection = Database.connect(conn_string, **self.options)
    8586            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    8687            self.connection.set_client_encoding('UTF8')
     88            connection_created.send(sender=self.__class__)
    8789        cursor = self.connection.cursor()
    8890        cursor.tzinfo_factory = None
    8991        if set_tz:
  • tests/regressiontests/backends/tests.py

     
     1from django.db import connection
     2from django.db.backends.signals import connection_created
     3from django.conf import settings
     4
     5def 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.
     13if 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()
     18connection_created signal
     19>>> connection_created.disconnect(connection_created_test)
     20>>> cursor = connection.cursor()
     21"""
Back to Top