Author: ramiro
Date: 2011-04-04 17:19:17 -0700 (Mon, 04 Apr 2011)
New Revision: 16016

Modified:
   django/trunk/django/contrib/gis/db/backends/oracle/operations.py
   django/trunk/django/contrib/gis/db/backends/spatialite/operations.py
   django/trunk/django/db/backends/__init__.py
   django/trunk/django/db/backends/dummy/base.py
   django/trunk/django/db/backends/mysql/base.py
   django/trunk/django/db/backends/oracle/base.py
   django/trunk/django/db/backends/postgresql_psycopg2/operations.py
   django/trunk/django/db/backends/sqlite3/base.py
   django/trunk/tests/regressiontests/backends/tests.py
Log:
Fixed #13630 -- Made __init__ methods of all DB backends' DatabaseOperations 
classes take a `connection` argument. Thanks calexium for the report.

Modified: django/trunk/django/contrib/gis/db/backends/oracle/operations.py
===================================================================
--- django/trunk/django/contrib/gis/db/backends/oracle/operations.py    
2011-04-04 15:43:56 UTC (rev 16015)
+++ django/trunk/django/contrib/gis/db/backends/oracle/operations.py    
2011-04-05 00:19:17 UTC (rev 16016)
@@ -133,8 +133,7 @@
     truncate_params = {'relate' : None}
 
     def __init__(self, connection):
-        super(OracleOperations, self).__init__()
-        self.connection = connection
+        super(OracleOperations, self).__init__(connection)
 
     def convert_extent(self, clob):
         if clob:

Modified: django/trunk/django/contrib/gis/db/backends/spatialite/operations.py
===================================================================
--- django/trunk/django/contrib/gis/db/backends/spatialite/operations.py        
2011-04-04 15:43:56 UTC (rev 16015)
+++ django/trunk/django/contrib/gis/db/backends/spatialite/operations.py        
2011-04-05 00:19:17 UTC (rev 16016)
@@ -110,8 +110,7 @@
     geometry_functions.update(distance_functions)
 
     def __init__(self, connection):
-        super(DatabaseOperations, self).__init__()
-        self.connection = connection
+        super(DatabaseOperations, self).__init__(connection)
 
         # Determine the version of the SpatiaLite library.
         try:

Modified: django/trunk/django/db/backends/__init__.py
===================================================================
--- django/trunk/django/db/backends/__init__.py 2011-04-04 15:43:56 UTC (rev 
16015)
+++ django/trunk/django/db/backends/__init__.py 2011-04-05 00:19:17 UTC (rev 
16016)
@@ -388,7 +388,8 @@
     """
     compiler_module = "django.db.models.sql.compiler"
 
-    def __init__(self):
+    def __init__(self, connection):
+        self.connection = connection
         self._cache = None
 
     def autoinc_sql(self, table, column):

Modified: django/trunk/django/db/backends/dummy/base.py
===================================================================
--- django/trunk/django/db/backends/dummy/base.py       2011-04-04 15:43:56 UTC 
(rev 16015)
+++ django/trunk/django/db/backends/dummy/base.py       2011-04-05 00:19:17 UTC 
(rev 16016)
@@ -59,7 +59,7 @@
         super(DatabaseWrapper, self).__init__(*args, **kwargs)
 
         self.features = BaseDatabaseFeatures(self)
-        self.ops = DatabaseOperations()
+        self.ops = DatabaseOperations(self)
         self.client = DatabaseClient(self)
         self.creation = BaseDatabaseCreation(self)
         self.introspection = DatabaseIntrospection(self)

Modified: django/trunk/django/db/backends/mysql/base.py
===================================================================
--- django/trunk/django/db/backends/mysql/base.py       2011-04-04 15:43:56 UTC 
(rev 16015)
+++ django/trunk/django/db/backends/mysql/base.py       2011-04-05 00:19:17 UTC 
(rev 16016)
@@ -23,7 +23,7 @@
     raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have 
%s" % Database.__version__)
 
 from MySQLdb.converters import conversions
-from MySQLdb.constants import FIELD_TYPE, FLAG, CLIENT
+from MySQLdb.constants import FIELD_TYPE, CLIENT
 
 from django.db import utils
 from django.db.backends import *
@@ -279,7 +279,7 @@
 
         self.server_version = None
         self.features = DatabaseFeatures(self)
-        self.ops = DatabaseOperations()
+        self.ops = DatabaseOperations(self)
         self.client = DatabaseClient(self)
         self.creation = DatabaseCreation(self)
         self.introspection = DatabaseIntrospection(self)

Modified: django/trunk/django/db/backends/oracle/base.py
===================================================================
--- django/trunk/django/db/backends/oracle/base.py      2011-04-04 15:43:56 UTC 
(rev 16015)
+++ django/trunk/django/db/backends/oracle/base.py      2011-04-05 00:19:17 UTC 
(rev 16016)
@@ -84,8 +84,8 @@
     def autoinc_sql(self, table, column):
         # To simulate auto-incrementing primary keys in Oracle, we have to
         # create a sequence and a trigger.
-        sq_name = get_sequence_name(table)
-        tr_name = get_trigger_name(table)
+        sq_name = self._get_sequence_name(table)
+        tr_name = self._get_trigger_name(table)
         tbl_name = self.quote_name(table)
         col_name = self.quote_name(column)
         sequence_sql = """
@@ -197,7 +197,7 @@
         return " DEFERRABLE INITIALLY DEFERRED"
 
     def drop_sequence_sql(self, table):
-        return "DROP SEQUENCE %s;" % self.quote_name(get_sequence_name(table))
+        return "DROP SEQUENCE %s;" % 
self.quote_name(self._get_sequence_name(table))
 
     def fetch_returned_insert_id(self, cursor):
         return long(cursor._insert_id_var.getvalue())
@@ -209,7 +209,7 @@
             return "%s"
 
     def last_insert_id(self, cursor, table_name, pk_name):
-        sq_name = get_sequence_name(table_name)
+        sq_name = self._get_sequence_name(table_name)
         cursor.execute('SELECT "%s".currval FROM dual' % sq_name)
         return cursor.fetchone()[0]
 
@@ -285,7 +285,7 @@
             # Since we've just deleted all the rows, running our sequence
             # ALTER code will reset the sequence to 0.
             for sequence_info in sequences:
-                sequence_name = get_sequence_name(sequence_info['table'])
+                sequence_name = self._get_sequence_name(sequence_info['table'])
                 table_name = self.quote_name(sequence_info['table'])
                 column_name = self.quote_name(sequence_info['column'] or 'id')
                 query = _get_sequence_reset_sql() % {'sequence': sequence_name,
@@ -304,7 +304,7 @@
             for f in model._meta.local_fields:
                 if isinstance(f, models.AutoField):
                     table_name = self.quote_name(model._meta.db_table)
-                    sequence_name = get_sequence_name(model._meta.db_table)
+                    sequence_name = 
self._get_sequence_name(model._meta.db_table)
                     column_name = self.quote_name(f.column)
                     output.append(query % {'sequence': sequence_name,
                                            'table': table_name,
@@ -315,7 +315,7 @@
             for f in model._meta.many_to_many:
                 if not f.rel.through:
                     table_name = self.quote_name(f.m2m_db_table())
-                    sequence_name = get_sequence_name(f.m2m_db_table())
+                    sequence_name = self._get_sequence_name(f.m2m_db_table())
                     column_name = self.quote_name('id')
                     output.append(query % {'sequence': sequence_name,
                                            'table': table_name,
@@ -365,7 +365,15 @@
             raise NotImplementedError("Bit-wise or is not supported in 
Oracle.")
         return super(DatabaseOperations, self).combine_expression(connector, 
sub_expressions)
 
+    def _get_sequence_name(self, table):
+        name_length = self.max_name_length() - 3
+        return '%s_SQ' % util.truncate_name(table, name_length).upper()
 
+    def _get_trigger_name(self, table):
+        name_length = self.max_name_length() - 3
+        return '%s_TR' % util.truncate_name(table, name_length).upper()
+
+
 class _UninitializedOperatorsDescriptor(object):
 
     def __get__(self, instance, owner):
@@ -415,7 +423,7 @@
         self.features = DatabaseFeatures(self)
         use_returning_into = 
self.settings_dict["OPTIONS"].get('use_returning_into', True)
         self.features.can_return_id_from_insert = use_returning_into
-        self.ops = DatabaseOperations()
+        self.ops = DatabaseOperations(self)
         self.client = DatabaseClient(self)
         self.creation = DatabaseCreation(self)
         self.introspection = DatabaseIntrospection(self)
@@ -776,13 +784,3 @@
     END LOOP;
 END;
 /"""
-
-
-def get_sequence_name(table):
-    name_length = DatabaseOperations().max_name_length() - 3
-    return '%s_SQ' % util.truncate_name(table, name_length).upper()
-
-
-def get_trigger_name(table):
-    name_length = DatabaseOperations().max_name_length() - 3
-    return '%s_TR' % util.truncate_name(table, name_length).upper()

Modified: django/trunk/django/db/backends/postgresql_psycopg2/operations.py
===================================================================
--- django/trunk/django/db/backends/postgresql_psycopg2/operations.py   
2011-04-04 15:43:56 UTC (rev 16015)
+++ django/trunk/django/db/backends/postgresql_psycopg2/operations.py   
2011-04-05 00:19:17 UTC (rev 16016)
@@ -5,9 +5,8 @@
 
 class DatabaseOperations(BaseDatabaseOperations):
     def __init__(self, connection):
-        super(DatabaseOperations, self).__init__()
+        super(DatabaseOperations, self).__init__(connection)
         self._postgres_version = None
-        self.connection = connection
 
     def _get_postgres_version(self):
         if self._postgres_version is None:

Modified: django/trunk/django/db/backends/sqlite3/base.py
===================================================================
--- django/trunk/django/db/backends/sqlite3/base.py     2011-04-04 15:43:56 UTC 
(rev 16015)
+++ django/trunk/django/db/backends/sqlite3/base.py     2011-04-05 00:19:17 UTC 
(rev 16016)
@@ -88,10 +88,10 @@
         # It would be more straightforward if we could use the sqlite strftime
         # function, but it does not allow for keeping six digits of fractional
         # second information, nor does it allow for formatting date and 
datetime
-        # values differently. So instead we register our own function that 
-        # formats the datetime combined with the delta in a manner suitable 
+        # values differently. So instead we register our own function that
+        # formats the datetime combined with the delta in a manner suitable
         # for comparisons.
-        return  u'django_format_dtdelta(%s, "%s", "%d", "%d", "%d")' % (sql, 
+        return  u'django_format_dtdelta(%s, "%s", "%d", "%d", "%d")' % (sql,
             connector, timedelta.days, timedelta.seconds, 
timedelta.microseconds)
 
     def date_trunc_sql(self, lookup_type, field_name):
@@ -179,7 +179,7 @@
         super(DatabaseWrapper, self).__init__(*args, **kwargs)
 
         self.features = DatabaseFeatures(self)
-        self.ops = DatabaseOperations()
+        self.ops = DatabaseOperations(self)
         self.client = DatabaseClient(self)
         self.creation = DatabaseCreation(self)
         self.introspection = DatabaseIntrospection(self)

Modified: django/trunk/tests/regressiontests/backends/tests.py
===================================================================
--- django/trunk/tests/regressiontests/backends/tests.py        2011-04-04 
15:43:56 UTC (rev 16015)
+++ django/trunk/tests/regressiontests/backends/tests.py        2011-04-05 
00:19:17 UTC (rev 16016)
@@ -232,7 +232,13 @@
         self.assertEqual(list(cursor.fetchmany(2)), [(u'Jane', u'Doe'), 
(u'John', u'Doe')])
         self.assertEqual(list(cursor.fetchall()), [(u'Mary', u'Agnelline'), 
(u'Peter', u'Parker')])
 
+    def test_database_operations_helper_class(self):
+        # Ticket #13630
+        self.assertTrue(hasattr(connection, 'ops'))
+        self.assertTrue(hasattr(connection.ops, 'connection'))
+        self.assertEqual(connection, connection.ops.connection)
 
+
 # We don't make these tests conditional because that means we would need to
 # check and differentiate between:
 # * MySQL+InnoDB, MySQL+MYISAM (something we currently can't do).

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to