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
This commit is contained in:
parent
adc9458541
commit
c4e0dc6b5e
|
@ -218,13 +218,15 @@ class BaseCommand(object):
|
||||||
output = self.handle(*args, **options)
|
output = self.handle(*args, **options)
|
||||||
if output:
|
if output:
|
||||||
if self.output_transaction:
|
if self.output_transaction:
|
||||||
# This needs to be imported here, because it relies on settings.
|
# This needs to be imported here, because it relies on
|
||||||
from django.db import connection
|
# settings.
|
||||||
|
from django.db import connections, DEFAULT_DB_ALIAS
|
||||||
|
connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
|
||||||
if connection.ops.start_transaction_sql():
|
if connection.ops.start_transaction_sql():
|
||||||
print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
|
print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
|
||||||
print output
|
print output
|
||||||
if self.output_transaction:
|
if self.output_transaction:
|
||||||
print self.style.SQL_KEYWORD("COMMIT;")
|
print self.style.SQL_KEYWORD(connection.ops.end_transaction_sql())
|
||||||
except CommandError, e:
|
except CommandError, e:
|
||||||
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
|
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -353,6 +353,11 @@ class BaseDatabaseOperations(object):
|
||||||
"""
|
"""
|
||||||
return "BEGIN;"
|
return "BEGIN;"
|
||||||
|
|
||||||
|
def end_transaction_sql(self, success=True):
|
||||||
|
if not success:
|
||||||
|
return "ROLLBACK;"
|
||||||
|
return "COMMIT;"
|
||||||
|
|
||||||
def tablespace_sql(self, tablespace, inline=False):
|
def tablespace_sql(self, tablespace, inline=False):
|
||||||
"""
|
"""
|
||||||
Returns the SQL that will be appended to tables or rows to define
|
Returns the SQL that will be appended to tables or rows to define
|
||||||
|
|
Loading…
Reference in New Issue