diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-05-28 13:46:12 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-05-28 13:46:12 +0000 |
| commit | c4e0dc6b5ea76d7f214b9e0d8ce02cc26375a798 (patch) | |
| tree | 7ca53ab8efd38804927e821f6a78f331536c961e | |
| parent | adc9458541385ce71935f328fa03cb7e48b8962e (diff) | |
Fixed #13656 -- Ensure that the management commands use the right database for transaction start/end commands. Thanks to Alex Gaynor for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13311 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/management/base.py | 8 | ||||
| -rw-r--r-- | django/db/backends/__init__.py | 5 |
2 files changed, 10 insertions, 3 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py index 4016faaa7a..a07fc7d56f 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -218,13 +218,15 @@ class BaseCommand(object): output = self.handle(*args, **options) if output: if self.output_transaction: - # This needs to be imported here, because it relies on settings. - from django.db import connection + # This needs to be imported here, because it relies on + # settings. + from django.db import connections, DEFAULT_DB_ALIAS + connection = connections[options.get('database', DEFAULT_DB_ALIAS)] 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;") + print self.style.SQL_KEYWORD(connection.ops.end_transaction_sql()) except CommandError, e: sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) sys.exit(1) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 5918935899..fe2c7c451b 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -353,6 +353,11 @@ class BaseDatabaseOperations(object): """ return "BEGIN;" + def end_transaction_sql(self, success=True): + if not success: + return "ROLLBACK;" + return "COMMIT;" + def tablespace_sql(self, tablespace, inline=False): """ Returns the SQL that will be appended to tables or rows to define |
