Ticket #13630: 13630.diff

File 13630.diff, 9.9 KB (added by Ramiro Morales, 14 years ago)

Patch for this issue, includes a test

  • django/contrib/gis/db/backends/oracle/operations.py

    diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py
    a b  
    133133    truncate_params = {'relate' : None}
    134134
    135135    def __init__(self, connection):
    136         super(OracleOperations, self).__init__()
    137         self.connection = connection
     136        super(OracleOperations, self).__init__(connection)
    138137
    139138    def convert_extent(self, clob):
    140139        if clob:
  • django/contrib/gis/db/backends/spatialite/operations.py

    diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py
    a b  
    110110    geometry_functions.update(distance_functions)
    111111
    112112    def __init__(self, connection):
    113         super(DatabaseOperations, self).__init__()
    114         self.connection = connection
     113        super(DatabaseOperations, self).__init__(connection)
    115114
    116115        # Determine the version of the SpatiaLite library.
    117116        try:
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    a b  
    388388    """
    389389    compiler_module = "django.db.models.sql.compiler"
    390390
    391     def __init__(self):
     391    def __init__(self, connection):
     392        self.connection = connection
    392393        self._cache = None
    393394
    394395    def autoinc_sql(self, table, column):
  • django/db/backends/dummy/base.py

    diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py
    a b  
    5959        super(DatabaseWrapper, self).__init__(*args, **kwargs)
    6060
    6161        self.features = BaseDatabaseFeatures(self)
    62         self.ops = DatabaseOperations()
     62        self.ops = DatabaseOperations(self)
    6363        self.client = DatabaseClient(self)
    6464        self.creation = BaseDatabaseCreation(self)
    6565        self.introspection = DatabaseIntrospection(self)
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    a b  
    2323    raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
    2424
    2525from MySQLdb.converters import conversions
    26 from MySQLdb.constants import FIELD_TYPE, FLAG, CLIENT
     26from MySQLdb.constants import FIELD_TYPE, CLIENT
    2727
    2828from django.db import utils
    2929from django.db.backends import *
     
    279279
    280280        self.server_version = None
    281281        self.features = DatabaseFeatures(self)
    282         self.ops = DatabaseOperations()
     282        self.ops = DatabaseOperations(self)
    283283        self.client = DatabaseClient(self)
    284284        self.creation = DatabaseCreation(self)
    285285        self.introspection = DatabaseIntrospection(self)
  • django/db/backends/oracle/base.py

    diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
    a b  
    8484    def autoinc_sql(self, table, column):
    8585        # To simulate auto-incrementing primary keys in Oracle, we have to
    8686        # create a sequence and a trigger.
    87         sq_name = get_sequence_name(table)
    88         tr_name = get_trigger_name(table)
     87        sq_name = self.get_sequence_name(table)
     88        tr_name = self.get_trigger_name(table)
    8989        tbl_name = self.quote_name(table)
    9090        col_name = self.quote_name(column)
    9191        sequence_sql = """
     
    197197        return " DEFERRABLE INITIALLY DEFERRED"
    198198
    199199    def drop_sequence_sql(self, table):
    200         return "DROP SEQUENCE %s;" % self.quote_name(get_sequence_name(table))
     200        return "DROP SEQUENCE %s;" % self.quote_name(self.get_sequence_name(table))
    201201
    202202    def fetch_returned_insert_id(self, cursor):
    203203        return long(cursor._insert_id_var.getvalue())
     
    209209            return "%s"
    210210
    211211    def last_insert_id(self, cursor, table_name, pk_name):
    212         sq_name = get_sequence_name(table_name)
     212        sq_name = self.get_sequence_name(table_name)
    213213        cursor.execute('SELECT "%s".currval FROM dual' % sq_name)
    214214        return cursor.fetchone()[0]
    215215
     
    285285            # Since we've just deleted all the rows, running our sequence
    286286            # ALTER code will reset the sequence to 0.
    287287            for sequence_info in sequences:
    288                 sequence_name = get_sequence_name(sequence_info['table'])
     288                sequence_name = self.get_sequence_name(sequence_info['table'])
    289289                table_name = self.quote_name(sequence_info['table'])
    290290                column_name = self.quote_name(sequence_info['column'] or 'id')
    291291                query = _get_sequence_reset_sql() % {'sequence': sequence_name,
     
    304304            for f in model._meta.local_fields:
    305305                if isinstance(f, models.AutoField):
    306306                    table_name = self.quote_name(model._meta.db_table)
    307                     sequence_name = get_sequence_name(model._meta.db_table)
     307                    sequence_name = self.get_sequence_name(model._meta.db_table)
    308308                    column_name = self.quote_name(f.column)
    309309                    output.append(query % {'sequence': sequence_name,
    310310                                           'table': table_name,
     
    315315            for f in model._meta.many_to_many:
    316316                if not f.rel.through:
    317317                    table_name = self.quote_name(f.m2m_db_table())
    318                     sequence_name = get_sequence_name(f.m2m_db_table())
     318                    sequence_name = self.get_sequence_name(f.m2m_db_table())
    319319                    column_name = self.quote_name('id')
    320320                    output.append(query % {'sequence': sequence_name,
    321321                                           'table': table_name,
     
    365365            raise NotImplementedError("Bit-wise or is not supported in Oracle.")
    366366        return super(DatabaseOperations, self).combine_expression(connector, sub_expressions)
    367367
     368    def get_sequence_name(self, table):
     369        name_length = self.max_name_length() - 3
     370        return '%s_SQ' % util.truncate_name(table, name_length).upper()
     371
     372    def get_trigger_name(self, table):
     373        name_length = self.max_name_length() - 3
     374        return '%s_TR' % util.truncate_name(table, name_length).upper()
     375
    368376
    369377class _UninitializedOperatorsDescriptor(object):
    370378
     
    415423        self.features = DatabaseFeatures(self)
    416424        use_returning_into = self.settings_dict["OPTIONS"].get('use_returning_into', True)
    417425        self.features.can_return_id_from_insert = use_returning_into
    418         self.ops = DatabaseOperations()
     426        self.ops = DatabaseOperations(self)
    419427        self.client = DatabaseClient(self)
    420428        self.creation = DatabaseCreation(self)
    421429        self.introspection = DatabaseIntrospection(self)
     
    776784    END LOOP;
    777785END;
    778786/"""
    779 
    780 
    781 def get_sequence_name(table):
    782     name_length = DatabaseOperations().max_name_length() - 3
    783     return '%s_SQ' % util.truncate_name(table, name_length).upper()
    784 
    785 
    786 def get_trigger_name(table):
    787     name_length = DatabaseOperations().max_name_length() - 3
    788     return '%s_TR' % util.truncate_name(table, name_length).upper()
  • django/db/backends/postgresql_psycopg2/operations.py

    diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
    a b  
    55
    66class DatabaseOperations(BaseDatabaseOperations):
    77    def __init__(self, connection):
    8         super(DatabaseOperations, self).__init__()
     8        super(DatabaseOperations, self).__init__(connection)
    99        self._postgres_version = None
    10         self.connection = connection
    1110
    1211    def _get_postgres_version(self):
    1312        if self._postgres_version is None:
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    a b  
    8888        # It would be more straightforward if we could use the sqlite strftime
    8989        # function, but it does not allow for keeping six digits of fractional
    9090        # second information, nor does it allow for formatting date and datetime
    91         # values differently. So instead we register our own function that 
    92         # formats the datetime combined with the delta in a manner suitable 
     91        # values differently. So instead we register our own function that
     92        # formats the datetime combined with the delta in a manner suitable
    9393        # for comparisons.
    94         return  u'django_format_dtdelta(%s, "%s", "%d", "%d", "%d")' % (sql, 
     94        return  u'django_format_dtdelta(%s, "%s", "%d", "%d", "%d")' % (sql,
    9595            connector, timedelta.days, timedelta.seconds, timedelta.microseconds)
    9696
    9797    def date_trunc_sql(self, lookup_type, field_name):
     
    179179        super(DatabaseWrapper, self).__init__(*args, **kwargs)
    180180
    181181        self.features = DatabaseFeatures(self)
    182         self.ops = DatabaseOperations()
     182        self.ops = DatabaseOperations(self)
    183183        self.client = DatabaseClient(self)
    184184        self.creation = DatabaseCreation(self)
    185185        self.introspection = DatabaseIntrospection(self)
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    a b  
    232232        self.assertEqual(list(cursor.fetchmany(2)), [(u'Jane', u'Doe'), (u'John', u'Doe')])
    233233        self.assertEqual(list(cursor.fetchall()), [(u'Mary', u'Agnelline'), (u'Peter', u'Parker')])
    234234
     235    def test_database_operations_helper_class(self):
     236        # Ticket #13630
     237        self.assertTrue(hasattr(connection, 'ops'))
     238        self.assertTrue(hasattr(connection.ops, 'connection'))
     239        self.assertEqual(connection, connection.ops.connection)
     240
    235241
    236242# We don't make these tests conditional because that means we would need to
    237243# check and differentiate between:
Back to Top