zendframework / zend-db

Db component from Zend Framework
BSD 3-Clause "New" or "Revised" License
101 stars 122 forks source link

Fix nested transaction issue with PDO driver #390

Closed michalbundyra closed 4 years ago

michalbundyra commented 5 years ago

Fixes #197, #385

For details please see related tickets.

/cc @danielhuang-030 @metalinspired @sorki @usuyukiso

michalbundyra commented 5 years ago

Actually I think it is still wrong, because for case:

beginTransaction
  execute QUERY1
  beginTransaction
    execute QUERY2
  rollback
  execute QUERY3
commit

all queries are going to be committed ... Need to think about better solution for this.

michalbundyra commented 5 years ago

I've added more test cases and I am even more confused and not sure if the fix is needed. Let me explain:

beginTransaction
  execute QUERY1
  beginTransaction
    execute QUERY2
  rollback
  execute QUERY3
commit

this is gonna throw an exception from the final commit as transaction is gonna be closed on the rollback. But in theory it should pass without errors, only QUERY2 should be rollbacked. But it's not possible in world without nested transactions.

Let consider now another example:

beginTransaction
  execute QUERY1
  beginTransaction
    execute QUERY2
  rollback
  execute QUERY3
rollback

and, previously (before fix), the second rollback here was failing for the same reason as commit in the first example. Now, this rollback is not failing but:

Based on that, I am not sure if any fix is needed. I would consider it as a limitation for PDO Driver.

The only problem I see is that we silently allowing open nested transaction, what is not allowed in PDO. We would get the exception straight away there if we try to open another transaction if the previous is still open. If we change the behaviour then probably all will be right. I mean, it will be not possible to do:

beginTransaction
   execute QUERY1
   beginTransaction <-- it will fail here as transaction cannot be nested.

/cc @Ocramius

michalbundyra commented 4 years ago

Closing as "won't fix", as PDO does not support nested transactions.