SQL Server: Isolation level leaks across pooled connections

The connection pool calls sp_resetconnection before recycling a connection. Resetting the transaction isolation level is not in the list of things that sp_resetconnection does. That would explain why “serializable” leaks across pooled connections. I guess you could start each query by making sure it’s at the right isolation level: if not exists ( select * … Read more

Is it possible to roll back CREATE TABLE and ALTER TABLE statements in major SQL databases?

http://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis provides an overview of this issue from PostgreSQL’s perspective. Is DDL transactional according to this document? PostgreSQL – yes MySQL – no; DDL causes an implicit commit Oracle Database 11g Release 2 and above – by default, no, but an alternative called edition-based redefinition exists Older versions of Oracle – no; DDL causes an … Read more

Django: How can I protect against concurrent modification of database entries

This is how I do optimistic locking in Django: updated = Entry.objects.filter(Q(id=e.id) && Q(version=e.version))\ .update(updated_field=new_value, version=e.version+1) if not updated: raise ConcurrentModificationException() The code listed above can be implemented as a method in Custom Manager. I am making the following assumptions: filter().update() will result in a single database query because filter is lazy a database query … Read more

@Transactional on @PostConstruct method

Quote from legacy (closed) Spring forum: In the @PostConstruct (as with the afterPropertiesSet from the InitializingBean interface) there is no way to ensure that all the post processing is already done, so (indeed) there can be no Transactions. The only way to ensure that that is working is by using a TransactionTemplate. So if you … Read more

Why do I need Transaction in Hibernate for read-only operations?

Transactions for reading might look indeed strange and often people don’t mark methods for transactions in this case. But JDBC will create transaction anyway, it’s just it will be working in autocommit=true if different option wasn’t set explicitly. But there are practical reasons to mark transactions read-only: Impact on databases Read-only flag may let DBMS … Read more

SQL Identity (autonumber) is Incremented Even with a Transaction Rollback

If you think about it, the auto-increment number should not be transactional. If other transactions had to wait to see if the auto-number was going to be used or “rolled back”, they would be blocked by the existing transaction using the auto-number. For example, consider my psuedo code below with table A using an auto-number … Read more

How to start and end transaction in mysqli?

Update Novembre 2020: @Dharman gave a better answer with more details about transactions in mysqli, just check it instead: https://stackoverflow.com/a/63764001/569101 👇 Well according to the php doc, you’re right. <?php $mysqli = new mysqli(“localhost”, “my_user”, “my_password”, “world”); /* check connection */ if (mysqli_connect_errno()) { printf(“Connect failed: %s\n”, mysqli_connect_error()); exit(); } $mysqli->query(“CREATE TABLE Language LIKE CountryLanguage”); … Read more