Problems? Is your data what you think it is? | |
PerlMonks |
Does each DBI 'do' start a new transaction?by Anonymous Monk |
on Mar 19, 2024 at 14:12 UTC ( [id://11158387]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: The following code when the 'update stock' condition returns 0, executes sql_error()'s sql 'insert into sql_error' AND dosql()'s 'insert into stock_valid' ,despite that the first statement of sql_error() is $dbh->rollback. I know that wrapping do_sql()'s sql statements in $dbh->begin_work would probably make it work, but I'm interested in the background of why it is happening.
I have a theory that every 'do' statement does start a new implicit transaction. So let's say that do(insert into stock_valid) is T1 and do(update stock) is T2. Then, T1 is rolled back when the rollback of sql_error() is hit, while T2 is not rolled back and instead is committed when $dbh->commit; of sql_error() is hit. My 2cents. What do you think?
Grandfather replaced pre tags with Code tags and fixed paragraphing.
Back to
Seekers of Perl Wisdom
|
|