Ticket #3460: autocommit-7624.patch
File autocommit-7624.patch, 4.2 KB (added by , 16 years ago) |
---|
-
django/db/backends/postgresql/base.py
83 83 } 84 84 85 85 def _cursor(self, settings): 86 set_tz= False86 first_cursor = False 87 87 if self.connection is None: 88 set_tz= True88 first_cursor = True 89 89 if settings.DATABASE_NAME == '': 90 90 from django.core.exceptions import ImproperlyConfigured 91 91 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") … … 99 99 if settings.DATABASE_PORT: 100 100 conn_string += " port=%s" % settings.DATABASE_PORT 101 101 self.connection = Database.connect(conn_string, **self.options) 102 self.connection.set_isolation_level( 1) # make transactions transparent to all cursors102 self.connection.set_isolation_level(0) 103 103 cursor = self.connection.cursor() 104 if set_tz:104 if first_cursor: 105 105 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 106 cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") 107 self._commit() 106 108 cursor.execute("SET client_encoding to 'UNICODE'") 107 109 cursor = UnicodeCursorWrapper(cursor, 'utf-8') 108 110 return cursor -
django/db/backends/postgresql_psycopg2/base.py
51 51 } 52 52 53 53 def _cursor(self, settings): 54 set_tz= False54 first_cursor = False 55 55 if self.connection is None: 56 set_tz= True56 first_cursor = True 57 57 if settings.DATABASE_NAME == '': 58 58 from django.core.exceptions import ImproperlyConfigured 59 59 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") … … 67 67 if settings.DATABASE_PORT: 68 68 conn_string += " port=%s" % settings.DATABASE_PORT 69 69 self.connection = Database.connect(conn_string, **self.options) 70 self.connection.set_isolation_level( 1) # make transactions transparent to all cursors70 self.connection.set_isolation_level(0) 71 71 self.connection.set_client_encoding('UTF8') 72 72 cursor = self.connection.cursor() 73 73 cursor.tzinfo_factory = None 74 if set_tz:74 if first_cursor: 75 75 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 76 cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") 77 self._commit() 76 78 return cursor -
django/core/management/commands/loaddata.py
9 9 except NameError: 10 10 from sets import Set as set # Python 2.3 fallback 11 11 12 def _set_transaction_mode(connection): 13 "Make sure a connection is not in autocommit mode." 14 if hasattr(connection.connection, "autocommit"): 15 connection.connection.autocommit(False) 16 elif hasattr(connection.connection, "set_isolation_level"): 17 connection.connection.set_isolation_level(1) 18 12 19 class Command(BaseCommand): 13 20 option_list = BaseCommand.option_list + ( 14 21 make_option('--verbosity', action='store', dest='verbosity', default='1', … … 41 48 # the side effect of initializing the test database (if 42 49 # it isn't already initialized). 43 50 cursor = connection.cursor() 51 _set_transaction_mode(connection) 44 52 45 53 # Start transaction management. All fixtures are installed in a 46 54 # single transaction to ensure that all references are resolved. … … 152 160 153 161 transaction.commit() 154 162 transaction.leave_transaction_management() 163 connection.close() 155 164 156 165 if object_count == 0: 157 166 if verbosity > 1: