Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #13630 -- Made __init__ methods of all DB backends' DatabaseOpe…

…rations classes take a `connection` argument. Thanks calexium for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16016 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 30b3d51599aed4cf08ccace9ba5b1277ded78439 1 parent 71bf169
@ramiro ramiro authored
View
3  django/contrib/gis/db/backends/oracle/operations.py
@@ -133,8 +133,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
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:
View
3  django/contrib/gis/db/backends/spatialite/operations.py
@@ -110,8 +110,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
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:
View
3  django/db/backends/__init__.py
@@ -388,7 +388,8 @@ class BaseDatabaseOperations(object):
"""
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):
View
2  django/db/backends/dummy/base.py
@@ -59,7 +59,7 @@ def __init__(self, *args, **kwargs):
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)
View
4 django/db/backends/mysql/base.py
@@ -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 @@ def __init__(self, *args, **kwargs):
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)
View
34 django/db/backends/oracle/base.py
@@ -84,8 +84,8 @@ class DatabaseOperations(BaseDatabaseOperations):
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 @@ def deferrable_sql(self):
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 @@ def field_cast_sql(self, db_type):
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 @@ def sql_flush(self, style, tables, sequences):
# 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 @@ def sequence_reset_sql(self, style, model_list):
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 @@ def sequence_reset_sql(self, style, model_list):
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,6 +365,14 @@ def combine_expression(self, connector, sub_expressions):
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):
@@ -415,7 +423,7 @@ def __init__(self, *args, **kwargs):
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 @@ def _get_sequence_reset_sql():
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()
View
3  django/db/backends/postgresql_psycopg2/operations.py
@@ -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:
View
8 django/db/backends/sqlite3/base.py
@@ -88,10 +88,10 @@ def date_interval_sql(self, sql, connector, timedelta):
# 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 @@ def __init__(self, *args, **kwargs):
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)
View
6 tests/regressiontests/backends/tests.py
@@ -232,6 +232,12 @@ def test_unicode_fetches(self):
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:

0 comments on commit 30b3d51

Please sign in to comment.
Something went wrong with that request. Please try again.