Ticket #13656: django-management-dbs.2.diff

File django-management-dbs.2.diff, 1.8 KB (added by Alex, 5 years ago)
  • django/core/management/base.py

    diff --git a/django/core/management/base.py b/django/core/management/base.py
    index 4016faa..a07fc7d 100644
    a b class BaseCommand(object): 
    218218            output = self.handle(*args, **options)
    219219            if output:
    220220                if self.output_transaction:
    221                     # This needs to be imported here, because it relies on settings.
    222                     from django.db import connection
     221                    # This needs to be imported here, because it relies on
     222                    # settings.
     223                    from django.db import connections, DEFAULT_DB_ALIAS
     224                    connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
    223225                    if connection.ops.start_transaction_sql():
    224226                        print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
    225227                print output
    226228                if self.output_transaction:
    227                     print self.style.SQL_KEYWORD("COMMIT;")
     229                    print self.style.SQL_KEYWORD(connection.ops.end_transaction_sql())
    228230        except CommandError, e:
    229231            sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
    230232            sys.exit(1)
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 5918935..a823503 100644
    a b class BaseDatabaseOperations(object): 
    352352        Returns the SQL statement required to start a transaction.
    353353        """
    354354        return "BEGIN;"
     355   
     356    def end_transaction_sql(self, fails=False):
     357        if fails:
     358            return "ROLLBACK;"
     359        return "COMMIT;"
    355360
    356361    def tablespace_sql(self, tablespace, inline=False):
    357362        """
Back to Top