Ticket #9206: extra_v2.diff
File extra_v2.diff, 2.6 KB (added by , 16 years ago) |
---|
-
docs/topics/db/transactions.txt
166 166 167 167 .. _information on MySQL transactions: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-transactions.html 168 168 169 Transactions and savepoints in PostgreSQL 8 170 =========================================== 169 Database exceptions within PostgreSQL transactions 170 ================================================== 171 171 172 When a call to a PostgreSQL 8cursor raises an exception, all subsequent SQL172 When a call to a PostgreSQL cursor raises an exception, all subsequent SQL 173 173 in the same transaction fails with the error "current transaction is aborted, 174 174 queries ignored until end of transaction block". Whilst simple use of save() 175 175 is unlikely to raise an exception in PostgreSQL, there are many more advanced 176 176 usage patterns which might: for example, saving objects with unique fields, 177 177 saving using the force_insert/force_update flag, or invoking custom SQL. 178 There are three possible solutions to this issue: 178 179 179 In any of these cases, you can wrap the command which may throw 180 IntegrityError inside savepoints, which will then allow subsequent commands 181 to proceed. Example:: 180 * With any version of PostgreSQL, you can rollback to the start of the 181 transaction if you experience an IntegrityError. 182 182 183 try: 184 sid = transaction.savepoint() 185 x.save() 186 transaction.savepoint_commit(sid) 187 except IntegrityError: 188 transaction.savepoint_rollback(sid) 189 raise 183 * With PostgreSQL 8 or later, you can wrap the command which may throw 184 IntegrityError inside savepoints, which will then allow subsequent 185 commands to proceed. Example:: 190 186 191 Savepoints are not implemented in PostgreSQL 7. If you experience an 192 IntegrityError when using PostgreSQL 7, you will need to rollback to the 193 start of the transaction. 187 try: 188 sid = transaction.savepoint() 189 x.save() 190 transaction.savepoint_commit(sid) 191 except IntegrityError: 192 transaction.savepoint_rollback(sid) 193 raise 194 195 .. versionadded:: 1.1 196 197 * With PostgreSQL 8.2 or later, there is an advanced option to run 198 PostgreSQL with :ref:`database-level autocommit <ref-databases>`. 199 With this option there is no constantly open transaction, so 200 savepoints are not required to continue after catching an exception. 201 Please see the documentation for that feature, which behaves 202 differently from the standard ``autocommit`` decorator.