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

File 6064-using-signals-3.diff, 6.4 KB (added by jbronn, 16 years ago)
  • 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
     
    114115                conn_string += " port=%s" % settings_dict['DATABASE_PORT']
    115116            self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS'])
    116117            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     118            connection_created.send(sender=self.__class__)
    117119        cursor = self.connection.cursor()
    118120        if set_tz:
    119121            cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
  • django/db/backends/sqlite3/base.py

     
    88"""
    99
    1010from django.db.backends import *
     11from django.db.backends.signals import connection_created
    1112from django.db.backends.sqlite3.client import DatabaseClient
    1213from django.db.backends.sqlite3.creation import DatabaseCreation
    1314from django.db.backends.sqlite3.introspection import DatabaseIntrospection
     
    171172            self.connection.create_function("django_extract", 2, _sqlite_extract)
    172173            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
    173174            self.connection.create_function("regexp", 2, _sqlite_regexp)
     175            connection_created.send(sender=self.__class__)
    174176        return self.connection.cursor(factory=SQLiteCursorWrapper)
    175177
    176178    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
     
    277278            self.connection = Database.connect(**kwargs)
    278279            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    279280            self.connection.encoders[SafeString] = self.connection.encoders[str]
     281            connection_created.send(sender=self.__class__)
    280282        cursor = CursorWrapper(self.connection.cursor())
    281283        return cursor
    282284
  • django/db/backends/oracle/base.py

     
    2525    raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
    2626
    2727from django.db.backends import *
     28from django.db.backends.signals import connection_created
    2829from django.db.backends.oracle import query
    2930from django.db.backends.oracle.client import DatabaseClient
    3031from django.db.backends.oracle.creation import DatabaseCreation
     
    329330                # Django docs specify cx_Oracle version 4.3.1 or higher, but
    330331                # stmtcachesize is available only in 4.3.2 and up.
    331332                pass
     333            connection_created.send(sender=self.__class__)
    332334        if not cursor:
    333335            cursor = FormatStylePlaceholderCursor(self.connection)
    334336        return cursor
  • django/db/backends/signals.py

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

     
    66
    77from django.conf import settings
    88from django.db.backends import *
     9from django.db.backends.signals import connection_created
    910from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations
    1011from django.db.backends.postgresql.client import DatabaseClient
    1112from django.db.backends.postgresql.creation import DatabaseCreation
     
    9697                conn_params['port'] = settings_dict['DATABASE_PORT']
    9798            self.connection = Database.connect(**conn_params)
    9899            self.connection.set_client_encoding('UTF8')
     100            connection_created.send(sender=self.__class__)
    99101        cursor = self.connection.cursor()
    100102        cursor.tzinfo_factory = None
    101103        if set_tz:
  • tests/regressiontests/backends/tests.py

     
    11# -*- coding: utf-8 -*-
    2 
    3 # Unit tests for specific database backends.
    4 
     2# Unit and doctests for specific database backends.
    53import unittest
    6 
    74from django.db import connection
     5from django.db.backends.signals import connection_created
    86from django.conf import settings
    97
    10 
    118class Callproc(unittest.TestCase):
    129
    1310    def test_dbms_session(self):
     
    2118        else:
    2219            return True
    2320
     21def connection_created_test(sender, **kwargs):
     22    print 'connection_created signal'
    2423
     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.
     29if 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()
     34connection_created signal
     35>>> connection_created.disconnect(connection_created_test)
     36>>> cursor = connection.cursor()
     37"""
     38
    2539if __name__ == '__main__':
    2640    unittest.main()
Back to Top