Code

Ticket #13656: django-management-dbs.diff

File django-management-dbs.diff, 1.6 KB (added by Alex, 4 years ago)
Line 
1diff --git a/django/core/management/base.py b/django/core/management/base.py
2index 4016faa..4afe500 100644
3--- a/django/core/management/base.py
4+++ b/django/core/management/base.py
5@@ -219,12 +219,13 @@ class BaseCommand(object):
6             if output:
7                 if self.output_transaction:
8                     # This needs to be imported here, because it relies on settings.
9-                    from django.db import connection
10+                    from django.db import connections
11+                    connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
12                     if connection.ops.start_transaction_sql():
13                         print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
14                 print output
15                 if self.output_transaction:
16-                    print self.style.SQL_KEYWORD("COMMIT;")
17+                    print self.style.SQL_KEYWORD(connection.ops.end_transaction_sql())
18         except CommandError, e:
19             sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
20             sys.exit(1)
21diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
22index 5918935..a823503 100644
23--- a/django/db/backends/__init__.py
24+++ b/django/db/backends/__init__.py
25@@ -352,6 +352,11 @@ class BaseDatabaseOperations(object):
26         Returns the SQL statement required to start a transaction.
27         """
28         return "BEGIN;"
29+   
30+    def end_transaction_sql(self, fails=False):
31+        if fails:
32+            return "ROLLBACK;"
33+        return "COMMIT;"
34 
35     def tablespace_sql(self, tablespace, inline=False):
36         """