Ticket #17760: 17760-5.diff
File 17760-5.diff, 8.9 KB (added by , 12 years ago) |
---|
-
django/contrib/gis/db/backends/spatialite/creation.py
diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py index 7efab3e..31f2fca 100644
a b class SpatiaLiteCreation(DatabaseCreation): 31 31 self.connection.close() 32 32 self.connection.settings_dict["NAME"] = test_database_name 33 33 34 # Confirm the feature set of the test database35 self.connection.features.confirm()36 37 34 # Need to load the SpatiaLite initialization SQL before running `syncdb`. 38 35 self.load_spatialite_sql() 39 36 -
django/db/backends/__init__.py
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index f26653f..d70fe54 100644
a b from django.conf import settings 10 10 from django.db import DEFAULT_DB_ALIAS 11 11 from django.db.backends import util 12 12 from django.db.transaction import TransactionManagementError 13 from django.utils.functional import cached_property 13 14 from django.utils.importlib import import_module 14 15 from django.utils.timezone import is_aware 15 16 … … class BaseDatabaseFeatures(object): 402 403 # Does the backend reset sequences between tests? 403 404 supports_sequence_reset = True 404 405 405 # Features that need to be confirmed at runtime 406 # Cache whether the confirmation has been performed. 407 _confirmed = False 408 supports_transactions = None 409 supports_stddev = None 410 can_introspect_foreign_keys = None 406 # Confirm support for introspected foreign keys 407 # Every database can do this reliably, except MySQL, 408 # which can't do it for MyISAM tables 409 can_introspect_foreign_keys = True 411 410 412 411 # Support for the DISTINCT ON clause 413 412 can_distinct_on_fields = False … … class BaseDatabaseFeatures(object): 415 414 def __init__(self, connection): 416 415 self.connection = connection 417 416 418 def confirm(self): 419 "Perform manual checks of any database features that might vary between installs" 420 if not self._confirmed: 421 self._confirmed = True 422 self.supports_transactions = self._supports_transactions() 423 self.supports_stddev = self._supports_stddev() 424 self.can_introspect_foreign_keys = self._can_introspect_foreign_keys() 425 426 def _supports_transactions(self): 417 @cached_property 418 def supports_transactions(self): 427 419 "Confirm support for transactions" 428 420 cursor = self.connection.cursor() 429 421 cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)') … … class BaseDatabaseFeatures(object): 436 428 self.connection._commit() 437 429 return count == 0 438 430 439 def _supports_stddev(self): 431 @cached_property 432 def supports_stddev(self): 440 433 "Confirm support for STDDEV and related stats functions" 441 434 class StdDevPop(object): 442 435 sql_function = 'STDDEV_POP' … … class BaseDatabaseFeatures(object): 447 440 except NotImplementedError: 448 441 return False 449 442 450 def _can_introspect_foreign_keys(self):451 "Confirm support for introspected foreign keys"452 # Every database can do this reliably, except MySQL,453 # which can't do it for MyISAM tables454 return True455 456 443 457 444 class BaseDatabaseOperations(object): 458 445 """ -
django/db/backends/creation.py
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index ba90cb9..0f06131 100644
a b class BaseDatabaseCreation(object): 264 264 self.connection.close() 265 265 self.connection.settings_dict["NAME"] = test_database_name 266 266 267 # Confirm the feature set of the test database268 self.connection.features.confirm()269 270 267 # Report syncdb messages at one level lower than that requested. 271 268 # This ensures we don't get flooded with messages during testing 272 269 # (unless you really ask to be flooded) -
django/db/backends/mysql/base.py
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 1df487b..1dbd91b 100644
a b from django.db.backends.mysql.client import DatabaseClient 36 36 from django.db.backends.mysql.creation import DatabaseCreation 37 37 from django.db.backends.mysql.introspection import DatabaseIntrospection 38 38 from django.db.backends.mysql.validation import DatabaseValidation 39 from django.utils.functional import cached_property 39 40 from django.utils.safestring import SafeString, SafeUnicode 40 41 from django.utils import timezone 41 42 … … class DatabaseFeatures(BaseDatabaseFeatures): 169 170 170 171 def __init__(self, connection): 171 172 super(DatabaseFeatures, self).__init__(connection) 172 self._storage_engine = None173 173 174 @cached_property 174 175 def _mysql_storage_engine(self): 175 176 "Internal method used in Django tests. Don't rely on this from your code" 176 if self._storage_engine is None: 177 cursor = self.connection.cursor() 178 cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)') 179 # This command is MySQL specific; the second column 180 # will tell you the default table type of the created 181 # table. Since all Django's test tables will have the same 182 # table type, that's enough to evaluate the feature. 183 cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'") 184 result = cursor.fetchone() 185 cursor.execute('DROP TABLE INTROSPECT_TEST') 186 self._storage_engine = result[1] 187 return self._storage_engine 188 189 def _can_introspect_foreign_keys(self): 177 cursor = self.connection.cursor() 178 cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)') 179 # This command is MySQL specific; the second column 180 # will tell you the default table type of the created 181 # table. Since all Django's test tables will have the same 182 # table type, that's enough to evaluate the feature. 183 cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'") 184 result = cursor.fetchone() 185 cursor.execute('DROP TABLE INTROSPECT_TEST') 186 return result[1] 187 188 @cached_property 189 def can_introspect_foreign_keys(self): 190 190 "Confirm support for introspected foreign keys" 191 return self._mysql_storage_engine ()!= 'MyISAM'191 return self._mysql_storage_engine != 'MyISAM' 192 192 193 193 class DatabaseOperations(BaseDatabaseOperations): 194 194 compiler_module = "django.db.backends.mysql.compiler" -
django/db/backends/sqlite3/base.py
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 4fba304..db6adde 100644
a b from django.db.backends.sqlite3.client import DatabaseClient 18 18 from django.db.backends.sqlite3.creation import DatabaseCreation 19 19 from django.db.backends.sqlite3.introspection import DatabaseIntrospection 20 20 from django.utils.dateparse import parse_date, parse_datetime, parse_time 21 from django.utils.functional import cached_property 21 22 from django.utils.safestring import SafeString 22 23 from django.utils import timezone 23 24 … … class DatabaseFeatures(BaseDatabaseFeatures): 85 86 has_bulk_insert = True 86 87 can_combine_inserts_with_and_without_auto_increment_pk = True 87 88 88 def _supports_stddev(self): 89 @cached_property 90 def supports_stddev(self): 89 91 """Confirm support for STDDEV and related stats functions 90 92 91 93 SQLite supports STDDEV as an extension package; so -
tests/regressiontests/backends/tests.py
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index 109e1a5..9bee987 100644
a b class BackendTestCase(TestCase): 403 403 self.assertTrue(hasattr(connection.ops, 'connection')) 404 404 self.assertEqual(connection, connection.ops.connection) 405 405 406 def test_supports_needed_confirm(self): 407 connection.features.confirm() 406 def test_cached_db_features(self): 408 407 self.assertIn(connection.features.supports_transactions, (True, False)) 409 408 self.assertIn(connection.features.supports_stddev, (True, False)) 410 409 self.assertIn(connection.features.can_introspect_foreign_keys, (True, False)) -
tests/regressiontests/transactions_regress/tests.py
diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py index 5972263..abd7a4c 100644
a b class SavepointTest(TransactionTestCase): 208 208 work() 209 209 210 210 @skipIf(connection.vendor == 'mysql' and \ 211 connection.features._mysql_storage_engine ()== 'MyISAM',211 connection.features._mysql_storage_engine == 'MyISAM', 212 212 "MyISAM MySQL storage engine doesn't support savepoints") 213 213 @skipUnlessDBFeature('uses_savepoints') 214 214 def test_savepoint_rollback(self):