Author: jbronn Date: 2009-03-29 18:15:58 -0500 (Sun, 29 Mar 2009) New Revision: 10182
Added: django/trunk/django/db/backends/signals.py Modified: django/trunk/django/db/backends/mysql/base.py django/trunk/django/db/backends/oracle/base.py django/trunk/django/db/backends/postgresql/base.py django/trunk/django/db/backends/postgresql_psycopg2/base.py django/trunk/django/db/backends/sqlite3/base.py django/trunk/tests/regressiontests/backends/tests.py Log: Fixed #6064 -- Added the `connection_created` signal for when a database connection is created. Modified: django/trunk/django/db/backends/mysql/base.py =================================================================== --- django/trunk/django/db/backends/mysql/base.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/django/db/backends/mysql/base.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -25,6 +25,7 @@ from MySQLdb.constants import FIELD_TYPE, FLAG from django.db.backends import * +from django.db.backends.signals import connection_created from django.db.backends.mysql.client import DatabaseClient from django.db.backends.mysql.creation import DatabaseCreation from django.db.backends.mysql.introspection import DatabaseIntrospection @@ -277,6 +278,7 @@ self.connection = Database.connect(**kwargs) self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] self.connection.encoders[SafeString] = self.connection.encoders[str] + connection_created.send(sender=self.__class__) cursor = CursorWrapper(self.connection.cursor()) return cursor Modified: django/trunk/django/db/backends/oracle/base.py =================================================================== --- django/trunk/django/db/backends/oracle/base.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/django/db/backends/oracle/base.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -25,6 +25,7 @@ raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e) from django.db.backends import * +from django.db.backends.signals import connection_created from django.db.backends.oracle import query from django.db.backends.oracle.client import DatabaseClient from django.db.backends.oracle.creation import DatabaseCreation @@ -329,6 +330,7 @@ # Django docs specify cx_Oracle version 4.3.1 or higher, but # stmtcachesize is available only in 4.3.2 and up. pass + connection_created.send(sender=self.__class__) if not cursor: cursor = FormatStylePlaceholderCursor(self.connection) return cursor Modified: django/trunk/django/db/backends/postgresql/base.py =================================================================== --- django/trunk/django/db/backends/postgresql/base.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/django/db/backends/postgresql/base.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -5,6 +5,7 @@ """ from django.db.backends import * +from django.db.backends.signals import connection_created from django.db.backends.postgresql.client import DatabaseClient from django.db.backends.postgresql.creation import DatabaseCreation from django.db.backends.postgresql.introspection import DatabaseIntrospection @@ -114,6 +115,7 @@ conn_string += " port=%s" % settings_dict['DATABASE_PORT'] self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS']) self.connection.set_isolation_level(1) # make transactions transparent to all cursors + connection_created.send(sender=self.__class__) cursor = self.connection.cursor() if set_tz: cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) Modified: django/trunk/django/db/backends/postgresql_psycopg2/base.py =================================================================== --- django/trunk/django/db/backends/postgresql_psycopg2/base.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/django/db/backends/postgresql_psycopg2/base.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -6,6 +6,7 @@ from django.conf import settings from django.db.backends import * +from django.db.backends.signals import connection_created from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations from django.db.backends.postgresql.client import DatabaseClient from django.db.backends.postgresql.creation import DatabaseCreation @@ -96,6 +97,7 @@ conn_params['port'] = settings_dict['DATABASE_PORT'] self.connection = Database.connect(**conn_params) self.connection.set_client_encoding('UTF8') + connection_created.send(sender=self.__class__) cursor = self.connection.cursor() cursor.tzinfo_factory = None if set_tz: Added: django/trunk/django/db/backends/signals.py =================================================================== --- django/trunk/django/db/backends/signals.py (rev 0) +++ django/trunk/django/db/backends/signals.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -0,0 +1,6 @@ +from django.dispatch import Signal + +connection_created = Signal() +from django.dispatch import Signal + +connection_created = Signal() Modified: django/trunk/django/db/backends/sqlite3/base.py =================================================================== --- django/trunk/django/db/backends/sqlite3/base.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/django/db/backends/sqlite3/base.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -8,6 +8,7 @@ """ from django.db.backends import * +from django.db.backends.signals import connection_created from django.db.backends.sqlite3.client import DatabaseClient from django.db.backends.sqlite3.creation import DatabaseCreation from django.db.backends.sqlite3.introspection import DatabaseIntrospection @@ -171,6 +172,7 @@ self.connection.create_function("django_extract", 2, _sqlite_extract) self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) self.connection.create_function("regexp", 2, _sqlite_regexp) + connection_created.send(sender=self.__class__) return self.connection.cursor(factory=SQLiteCursorWrapper) def close(self): Modified: django/trunk/tests/regressiontests/backends/tests.py =================================================================== --- django/trunk/tests/regressiontests/backends/tests.py 2009-03-29 23:05:51 UTC (rev 10181) +++ django/trunk/tests/regressiontests/backends/tests.py 2009-03-29 23:15:58 UTC (rev 10182) @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- - -# Unit tests for specific database backends. - +# Unit and doctests for specific database backends. import unittest - from django.db import connection +from django.db.backends.signals import connection_created from django.conf import settings - class Callproc(unittest.TestCase): def test_dbms_session(self): @@ -21,6 +18,23 @@ else: return True +def connection_created_test(sender, **kwargs): + print 'connection_created signal' +__test__ = {'API_TESTS': ''} + +# Unfortunately with sqlite3 the in-memory test database cannot be +# closed, and so it cannot be re-opened during testing, and so we +# sadly disable this test for now. +if settings.DATABASE_ENGINE != 'sqlite3': + __test__['API_TESTS'] += """ +>>> connection_created.connect(connection_created_test) +>>> connection.close() # Ensure the connection is closed +>>> cursor = connection.cursor() +connection_created signal +>>> connection_created.disconnect(connection_created_test) +>>> cursor = connection.cursor() +""" + if __name__ == '__main__': unittest.main() --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---