From 13061bf20bc467c5655c2dfa280dc226a00effcd Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 20 Aug 2007 00:24:03 +0000 Subject: [PATCH] Refactored get_start_transaction_sql() to DatabaseOperations.start_transaction_sql(). Refs #5106 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5965 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management/base.py | 6 +++--- django/db/backends/__init__.py | 6 ++++++ django/db/backends/ado_mssql/base.py | 3 --- django/db/backends/dummy/base.py | 1 - django/db/backends/mysql/base.py | 3 --- django/db/backends/mysql_old/base.py | 3 --- django/db/backends/oracle/base.py | 6 +++--- django/db/backends/postgresql/base.py | 3 --- django/db/backends/postgresql_psycopg2/base.py | 3 --- django/db/backends/sqlite3/base.py | 3 --- 10 files changed, 12 insertions(+), 25 deletions(-) diff --git a/django/core/management/base.py b/django/core/management/base.py index 3b88234a94..866dec4407 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -34,9 +34,9 @@ class BaseCommand(object): if output: if self.output_transaction: # This needs to be imported here, because it relies on settings. - from django.db import backend - if backend.get_start_transaction_sql(): - print self.style.SQL_KEYWORD(backend.get_start_transaction_sql()) + from django.db import connection + if connection.ops.start_transaction_sql(): + print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()) print output if self.output_transaction: print self.style.SQL_KEYWORD("COMMIT;") diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 07a645307f..8af82a4dda 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -160,3 +160,9 @@ class BaseDatabaseOperations(object): color_style() or no_style() in django.core.management.color. """ return [] # No sequence reset required by default. + + def start_transaction_sql(self): + """ + Returns the SQL statement required to start a transaction. + """ + return "BEGIN;" diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index 478ad9afda..192c069449 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/django/db/backends/ado_mssql/base.py @@ -103,9 +103,6 @@ dictfetchone = util.dictfetchone dictfetchmany = util.dictfetchmany dictfetchall = util.dictfetchall -def get_start_transaction_sql(): - return "BEGIN;" - def get_tablespace_sql(tablespace, inline=False): return "ON %s" % quote_name(tablespace) diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index 4bc965ac43..9339d87bf3 100644 --- a/django/db/backends/dummy/base.py +++ b/django/db/backends/dummy/base.py @@ -43,6 +43,5 @@ quote_name = complain dictfetchone = complain dictfetchmany = complain dictfetchall = complain -get_start_transaction_sql = complain OPERATOR_MAPPING = {} diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 6096700296..3af055ba8d 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -188,9 +188,6 @@ dictfetchone = util.dictfetchone dictfetchmany = util.dictfetchmany dictfetchall = util.dictfetchall -def get_start_transaction_sql(): - return "BEGIN;" - OPERATOR_MAPPING = { 'exact': '= %s', 'iexact': 'LIKE %s', diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index babf805304..935f92fcaf 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -207,9 +207,6 @@ dictfetchone = util.dictfetchone dictfetchmany = util.dictfetchmany dictfetchall = util.dictfetchall -def get_start_transaction_sql(): - return "BEGIN;" - OPERATOR_MAPPING = { 'exact': '= %s', 'iexact': 'LIKE %s', diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 9d9305d3f8..b84dc48bbe 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -112,6 +112,9 @@ class DatabaseOperations(BaseDatabaseOperations): 'table':f.m2m_db_table()}) return output + def start_transaction_sql(self): + return '' + class DatabaseWrapper(BaseDatabaseWrapper): ops = DatabaseOperations() @@ -228,9 +231,6 @@ def get_field_cast_sql(db_type): else: return "%s%s" -def get_start_transaction_sql(): - return None - def get_tablespace_sql(tablespace, inline=False): return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), quote_name(tablespace)) diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 1ff5003129..9ce5890728 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -211,9 +211,6 @@ def dictfetchall(cursor): "Returns all rows from a cursor as a dict" return cursor.dictfetchall() -def get_start_transaction_sql(): - return "BEGIN;" - def typecast_string(s): """ Cast all returned strings to unicode strings. diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index ac1c5a2a55..4bd64cda78 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -165,9 +165,6 @@ dictfetchone = util.dictfetchone dictfetchmany = util.dictfetchmany dictfetchall = util.dictfetchall -def get_start_transaction_sql(): - return "BEGIN;" - OPERATOR_MAPPING = { 'exact': '= %s', 'iexact': 'ILIKE %s', diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 3c35cb200d..a48ff3a93c 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -131,9 +131,6 @@ def _sqlite_extract(lookup_type, dt): return None return str(getattr(dt, lookup_type)) -def get_start_transaction_sql(): - return "BEGIN;" - def _sqlite_date_trunc(lookup_type, dt): try: dt = util.typecast_timestamp(dt)