Ticket #17760: 17760-4.diff

File 17760-4.diff, 7.6 KB (added by Ramiro Morales, 13 years ago)

Fixed problem with detction of STDDEV on sqlite3

  • django/contrib/gis/db/backends/spatialite/creation.py

    diff -r e6ff4cef36b7 django/contrib/gis/db/backends/spatialite/creation.py
    a b  
    3131        self.connection.close()
    3232        self.connection.settings_dict["NAME"] = test_database_name
    3333
    34         # Confirm the feature set of the test database
    35         self.connection.features.confirm()
    36 
    3734        # Need to load the SpatiaLite initialization SQL before running `syncdb`.
    3835        self.load_spatialite_sql()
    3936
  • django/db/backends/__init__.py

    diff -r e6ff4cef36b7 django/db/backends/__init__.py
    a b  
    1010from django.db import DEFAULT_DB_ALIAS
    1111from django.db.backends import util
    1212from django.db.transaction import TransactionManagementError
     13from django.utils.functional import cached_property
    1314from django.utils.importlib import import_module
    1415from django.utils.timezone import is_aware
    1516
     
    399400    # in the SQL standard.
    400401    supports_tablespaces = False
    401402
    402     # Features that need to be confirmed at runtime
    403     # Cache whether the confirmation has been performed.
    404     _confirmed = False
    405     supports_transactions = None
    406     supports_stddev = None
    407     can_introspect_foreign_keys = None
     403    # Confirm support for introspected foreign keys
     404    # Every database can do this reliably, except MySQL,
     405    # which can't do it for MyISAM tables
     406    can_introspect_foreign_keys = True
    408407
    409408    # Support for the DISTINCT ON clause
    410409    can_distinct_on_fields = False
     
    412411    def __init__(self, connection):
    413412        self.connection = connection
    414413
    415     def confirm(self):
    416         "Perform manual checks of any database features that might vary between installs"
    417         self._confirmed = True
    418         self.supports_transactions = self._supports_transactions()
    419         self.supports_stddev = self._supports_stddev()
    420         self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
    421 
    422     def _supports_transactions(self):
     414    @cached_property
     415    def supports_transactions(self):
    423416        "Confirm support for transactions"
    424417        cursor = self.connection.cursor()
    425418        cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
     
    432425        self.connection._commit()
    433426        return count == 0
    434427
    435     def _supports_stddev(self):
     428    @cached_property
     429    def supports_stddev(self):
    436430        "Confirm support for STDDEV and related stats functions"
    437431        class StdDevPop(object):
    438432            sql_function = 'STDDEV_POP'
     
    440434        try:
    441435            self.connection.ops.check_aggregate_support(StdDevPop())
    442436        except NotImplementedError:
    443             self.supports_stddev = False
    444 
    445     def _can_introspect_foreign_keys(self):
    446         "Confirm support for introspected foreign keys"
    447         # Every database can do this reliably, except MySQL,
    448         # which can't do it for MyISAM tables
     437            return False
    449438        return True
    450439
    451440
  • django/db/backends/creation.py

    diff -r e6ff4cef36b7 django/db/backends/creation.py
    a b  
    258258        self.connection.close()
    259259        self.connection.settings_dict["NAME"] = test_database_name
    260260
    261         # Confirm the feature set of the test database
    262         self.connection.features.confirm()
    263 
    264261        # Report syncdb messages at one level lower than that requested.
    265262        # This ensures we don't get flooded with messages during testing
    266263        # (unless you really ask to be flooded)
  • django/db/backends/mysql/base.py

    diff -r e6ff4cef36b7 django/db/backends/mysql/base.py
    a b  
    3333from django.db.backends.mysql.creation import DatabaseCreation
    3434from django.db.backends.mysql.introspection import DatabaseIntrospection
    3535from django.db.backends.mysql.validation import DatabaseValidation
     36from django.utils.functional import cached_property
    3637from django.utils.safestring import SafeString, SafeUnicode
    3738from django.utils import timezone
    3839
     
    166167
    167168    def __init__(self, connection):
    168169        super(DatabaseFeatures, self).__init__(connection)
    169         self._storage_engine = None
    170170
     171    @cached_property
    171172    def _mysql_storage_engine(self):
    172173        "Internal method used in Django tests. Don't rely on this from your code"
    173         if self._storage_engine is None:
    174             cursor = self.connection.cursor()
    175             cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
    176             # This command is MySQL specific; the second column
    177             # will tell you the default table type of the created
    178             # table. Since all Django's test tables will have the same
    179             # table type, that's enough to evaluate the feature.
    180             cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'")
    181             result = cursor.fetchone()
    182             cursor.execute('DROP TABLE INTROSPECT_TEST')
    183             self._storage_engine = result[1]
    184         return self._storage_engine
     174        cursor = self.connection.cursor()
     175        cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
     176        # This command is MySQL specific; the second column
     177        # will tell you the default table type of the created
     178        # table. Since all Django's test tables will have the same
     179        # table type, that's enough to evaluate the feature.
     180        cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'")
     181        result = cursor.fetchone()
     182        cursor.execute('DROP TABLE INTROSPECT_TEST')
     183        return result[1]
    185184
    186     def _can_introspect_foreign_keys(self):
     185    @cached_property
     186    def can_introspect_foreign_keys(self):
    187187        "Confirm support for introspected foreign keys"
    188         return self._mysql_storage_engine() != 'MyISAM'
     188        return self._mysql_storage_engine != 'MyISAM'
    189189
    190190class DatabaseOperations(BaseDatabaseOperations):
    191191    compiler_module = "django.db.backends.mysql.compiler"
  • django/db/backends/sqlite3/base.py

    diff -r e6ff4cef36b7 django/db/backends/sqlite3/base.py
    a b  
    1818from django.db.backends.sqlite3.creation import DatabaseCreation
    1919from django.db.backends.sqlite3.introspection import DatabaseIntrospection
    2020from django.utils.dateparse import parse_date, parse_datetime, parse_time
     21from django.utils.functional import cached_property
    2122from django.utils.safestring import SafeString
    2223from django.utils import timezone
    2324
     
    8586    has_bulk_insert = True
    8687    can_combine_inserts_with_and_without_auto_increment_pk = True
    8788
    88     def _supports_stddev(self):
     89    @cached_property
     90    def supports_stddev(self):
    8991        """Confirm support for STDDEV and related stats functions
    9092
    9193        SQLite supports STDDEV as an extension package; so
  • tests/regressiontests/transactions_regress/tests.py

    diff -r e6ff4cef36b7 tests/regressiontests/transactions_regress/tests.py
    a b  
    208208        work()
    209209
    210210    @skipIf(connection.vendor == 'mysql' and \
    211             connection.features._mysql_storage_engine() == 'MyISAM',
     211            connection.features._mysql_storage_engine == 'MyISAM',
    212212            "MyISAM MySQL storage engine doesn't support savepoints")
    213213    @skipUnlessDBFeature('uses_savepoints')
    214214    def test_savepoint_rollback(self):
Back to Top