Ticket #13798: django-connection-created.diff
File django-connection-created.diff, 8.9 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/db/backends/spatialite/base.py
diff --git a/django/contrib/gis/db/backends/spatialite/base.py b/django/contrib/gis/db/backends/spatialite/base.py index d419dab..729fc15 100644
a b class DatabaseWrapper(SqliteDatabaseWrapper): 51 51 self.connection.create_function("django_extract", 2, _sqlite_extract) 52 52 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 53 53 self.connection.create_function("regexp", 2, _sqlite_regexp) 54 connection_created.send(sender=self.__class__ )54 connection_created.send(sender=self.__class__, connection=self) 55 55 56 56 ## From here on, customized for GeoDjango ## 57 57 -
django/db/backends/mysql/base.py
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index e94e24b..a39c41f 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 297 297 self.connection = Database.connect(**kwargs) 298 298 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 299 299 self.connection.encoders[SafeString] = self.connection.encoders[str] 300 connection_created.send(sender=self.__class__ )300 connection_created.send(sender=self.__class__, connection=self) 301 301 cursor = CursorWrapper(self.connection.cursor()) 302 302 return cursor 303 303 -
django/db/backends/oracle/base.py
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 369e65b..0cf26c4 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 384 384 # Django docs specify cx_Oracle version 4.3.1 or higher, but 385 385 # stmtcachesize is available only in 4.3.2 and up. 386 386 pass 387 connection_created.send(sender=self.__class__ )387 connection_created.send(sender=self.__class__, connection=self) 388 388 if not cursor: 389 389 cursor = FormatStylePlaceholderCursor(self.connection) 390 390 return cursor -
django/db/backends/postgresql/base.py
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index a1c858b..f84ad1d 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 135 135 if settings_dict['PORT']: 136 136 conn_string += " port=%s" % settings_dict['PORT'] 137 137 self.connection = Database.connect(conn_string, **settings_dict['OPTIONS']) 138 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 139 connection_created.send(sender=self.__class__) 138 # make transactions transparent to all cursors 139 self.connection.set_isolation_level(1) 140 connection_created.send(sender=self.__class__, connection=self) 140 141 cursor = self.connection.cursor() 141 142 if new_connection: 142 143 if set_tz: -
django/db/backends/postgresql_psycopg2/base.py
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 29b7e7f..ce4e483 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 136 136 self.connection = Database.connect(**conn_params) 137 137 self.connection.set_client_encoding('UTF8') 138 138 self.connection.set_isolation_level(self.isolation_level) 139 connection_created.send(sender=self.__class__ )139 connection_created.send(sender=self.__class__, connection=self) 140 140 cursor = self.connection.cursor() 141 141 cursor.tzinfo_factory = None 142 142 if new_connection: -
django/db/backends/signals.py
diff --git a/django/db/backends/signals.py b/django/db/backends/signals.py index a8079d0..fa411d7 100644
a b 1 1 from django.dispatch import Signal 2 2 3 connection_created = Signal( )3 connection_created = Signal(["connection"]) -
django/db/backends/sqlite3/base.py
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index bc97f5c..1ab2557 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 176 176 self.connection.create_function("django_extract", 2, _sqlite_extract) 177 177 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 178 178 self.connection.create_function("regexp", 2, _sqlite_regexp) 179 connection_created.send(sender=self.__class__ )179 connection_created.send(sender=self.__class__, connection=self) 180 180 return self.connection.cursor(factory=SQLiteCursorWrapper) 181 181 182 182 def close(self): -
tests/regressiontests/backends/tests.py
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index 6a26a60..6855162 100644
a b 1 1 # -*- coding: utf-8 -*- 2 2 # Unit and doctests for specific database backends. 3 3 import datetime 4 import models5 4 import unittest 5 6 from django.conf import settings 6 7 from django.db import backend, connection, DEFAULT_DB_ALIAS 7 8 from django.db.backends.signals import connection_created 8 from django. conf import settings9 from django.db.backends.postgresql import version as pg_version 9 10 from django.test import TestCase 10 11 11 class Callproc(unittest.TestCase): 12 import models 12 13 14 15 class Callproc(unittest.TestCase): 13 16 def test_dbms_session(self): 14 17 # If the backend is Oracle, test that we can call a standard 15 18 # stored procedure through our cursor wrapper. … … class ParameterHandlingTest(TestCase): 88 91 self.assertRaises(Exception, cursor.executemany, query, [(1,2,3),]) 89 92 self.assertRaises(Exception, cursor.executemany, query, [(1,),]) 90 93 91 92 def connection_created_test(sender, **kwargs): 93 print 'connection_created signal' 94 95 __test__ = {'API_TESTS': """ 96 # Check Postgres version parsing 97 >>> from django.db.backends.postgresql import version as pg_version 98 99 >>> pg_version._parse_version("PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)") 100 (8, 3, 1) 101 102 >>> pg_version._parse_version("PostgreSQL 8.3.6") 103 (8, 3, 6) 104 105 >>> pg_version._parse_version("PostgreSQL 8.3") 106 (8, 3, None) 107 108 >>> pg_version._parse_version("EnterpriseDB 8.3") 109 (8, 3, None) 110 111 >>> pg_version._parse_version("PostgreSQL 8.3 beta4") 112 (8, 3, None) 113 114 >>> pg_version._parse_version("PostgreSQL 8.4beta1") 115 (8, 4, None) 116 117 """} 118 119 # Unfortunately with sqlite3 the in-memory test database cannot be 120 # closed, and so it cannot be re-opened during testing, and so we 121 # sadly disable this test for now. 122 if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.sqlite3': 123 __test__['API_TESTS'] += """ 124 >>> connection_created.connect(connection_created_test) 125 >>> connection.close() # Ensure the connection is closed 126 >>> cursor = connection.cursor() 127 connection_created signal 128 >>> connection_created.disconnect(connection_created_test) 129 >>> cursor = connection.cursor() 130 """ 131 132 if __name__ == '__main__': 133 unittest.main() 94 class PostgresVersionTest(TestCase): 95 def assert_parses(self, version_string, version): 96 self.assertEqual(pg_version._parse_version(version_string), version) 97 98 def test_parsing(self): 99 self.assert_parses( 100 "PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)", 101 (8, 3, 1) 102 ) 103 104 self.assert_parses( 105 "PostgreSQL 8.3.6", 106 (8, 3, 6) 107 ) 108 109 self.assert_parses( 110 "PostgreSQL 8.3", 111 (8, 3, None) 112 ) 113 114 self.assert_parses( 115 "EnterpriseDB 8.3", 116 (8, 3, None) 117 ) 118 119 self.assert_parses( 120 "PostgreSQL 8.3 beta4", 121 (8, 3, None) 122 ) 123 124 self.assert_parses( 125 "PostgreSQL 8.4beta1", 126 (8, 4, None) 127 ) 128 129 # Unfortunately with sqlite3 the in-memory test database cannot be closed, and 130 # so it cannot be re-opened during testing, and so we sadly disable this test 131 # for now. 132 if settings.DATABASES[DEFAULT_DB_ALIAS]["ENGINE"] != "django.db.backends.sqlite3": 133 class ConnectionCreatedSignalTest(TestCase): 134 def test_signal(self): 135 data = {} 136 def receiver(sender, connection, **kwargs): 137 data["connection"] = connection 138 139 connection_created.connect(receiver) 140 connection.close() 141 cursor = connection.cursor() 142 self.assertTrue(data["connection"] is connection) 143 144 connection_created.disconnect(receiver) 145 data.clear() 146 cursor = connection.cursor() 147 self.assertTrue(data == {})