AFAIK, DM doesn't support nested transactions.  Also AFAICT the only DB that 
supports true nested transactions (natively via START TRANSACTION/BEGIN SQL 
primitive) is SQL Server.  MySQL supports them via different SQL primitives 
called "savepoints".  I don't think SQLite has them, but I'd bet that 
Postgresql does, in some form or another.

I recently looked into why DM doesn't support them (while AR does), and I came 
to two basic conclusions:

        (1) Nested transaction support (on a per-adapter basis) is totally 
possible by switching transaction SQL primitive based on the level of 
transactional nesting level in effect for a given repository connection.  For 
example, in MySQL the first transaction would use a BEGIN (like it does now) 
while subsequent (nested) transactions would instead use SAVEPOINT.

        (2) The separation of DO (which currently manages transaction SQL 
primitives) and DM (the layer that actually knows about query scope & nesting 
level) makes this harder than it is in AR (which doesn't have this separation).

All that's necessary would be to track current transaction level on a given 
repository connection, add a standard ID-tag for every transaction (for 
savepoint references), and depending on nesting level switch between (in MySQL) 
BEGIN vs. SAVEPOINT and their corollary COMMIT/ROLLBACK mechanisms.

I don't know if this is even on the current list of priorities, but it'd be 
nice: I haven't found an easy way to use transactions in testing frameworks to 
reset DB state quickly when doing functional testing of controller methods that 
employ transactions themselves.

cheers,
--jordan


On Dec 28, 2009, at 8:24 AM, Kai Chen wrote:

> Hi all.
> 
> I found could not use nested transaction any more in datamapper 0.10.x.
> 
> And seems this commit force dm use regular transactions
> http://github.com/datamapper/dm-core/commit/1a0edcdccba4d9540b42bbd2cc5ae239fbe1d296
> 
> So when you use start a transaction and modify data in other
> transaction, it will got this error `Lock wait timeout exceeded; try
> restarting transaction - (DataObjects::SQLError)`.
> 
> --
> Regards,
> Kai Chen
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/datamapper?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.


Reply via email to