[Dbix-class] transactions, etc.
Josef Karthauser
joe at tao.org.uk
Thu Jan 25 14:27:53 GMT 2007
On Wed, Jan 24, 2007 at 12:22:49PM -0600, Brandon Black wrote:
> >
> >Nope, I'm talking about the -current branch. I think that the code when
> >it reconnections should check to see whether the internal transaction
> >count is non-zero, and if it raise an exception instead of proceeding.
> >That would be the safest thing to do.
> >
>
> In the txn_begin/txn_end case that's true, although it needs some
> careful thought and testing. However, txn_do is much more robust, and
> I don't believe it currently suffers from this problem.
>
Ok. First things first. It appears that some of the dependancy code
isn't working properly.
Look at this patch:
=== Storage/DBI/mysql.pm
==================================================================
--- Storage/DBI/mysql.pm (revision 3050)
+++ Storage/DBI/mysql.pm (local)
@@ -7,6 +7,10 @@
# __PACKAGE__->load_components(qw/PK::Auto/);
+sub _dbh_txn_begin {
+ print "mysql:_dbh_txn_begin\n";
+}
+
sub _dbh_last_insert_id {
my ($self, $dbh, $source, $col) = @_;
$dbh->{mysql_insertid};
=== Storage/DBI.pm
==================================================================
--- Storage/DBI.pm (revision 3050)
+++ Storage/DBI.pm (local)
@@ -741,6 +741,7 @@
sub _dbh_txn_begin {
my ($self, $dbh) = @_;
+print "storage:_dbh_txn_begin\n";
if ($dbh->{AutoCommit}) {
$self->debugobj->txn_begin()
if ($self->debug);
@@ -750,8 +751,10 @@
sub txn_begin {
my $self = shift;
- $self->dbh_do($self->can('_dbh_txn_begin'))
- if $self->{transaction_depth}++ == 0;
+print "storage:txn_begin\n";
+# $self->dbh_do($self->can('_dbh_txn_begin'))
+# if $self->{transaction_depth}++ == 0;
+ $self->dbh_do($self->can('_dbh_txn_begin'));
}
sub _dbh_txn_commit {
The point here being to see if I can override _dbh_txn_commit in the
database specific driver file (mysql in this case).
However with this test code:
my $schema = .... however you get your schema ...;
$schema->txn_begin();
print "A\n";
$schema->txn_begin();
print "A2\n";
$schema->txn_begin();
print "A3\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R3\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R2\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R1\n";
$schema->txn_begin();
print "A\n";
$schema->txn_begin();
print "A2\n";
$schema->txn_begin();
print "A3\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R3\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R2\n";
eval { $schema->txn_rollback(); }; print Dumper $@;
print "R1\n";
I get this output:
transwarp% env DBIC_TRACE=1 ./test.pl
storage:txn_begin
storage:_dbh_txn_begin
BEGIN WORK
A
storage:txn_begin
mysql:_dbh_txn_begin
A2
storage:txn_begin
mysql:_dbh_txn_begin
A3
ROLLBACK
$VAR1 = '';
R3
$VAR1 = '';
R2
$VAR1 = '';
R1
storage:txn_begin
mysql:_dbh_txn_begin
A
storage:txn_begin
mysql:_dbh_txn_begin
A2
storage:txn_begin
mysql:_dbh_txn_begin
A3
$VAR1 = '';
R3
$VAR1 = '';
R2
$VAR1 = '';
R1
Notice that the first time that txn_begin is called it isn't calling the
code in ...::DBI::mysql, however it does subsequently.
I've not totally got my head around the auto loading code yet, but it
appears that the ...:DBI::driver code is being loaded too late.
It ought to be auto loaded when the schema object is populated, not
when the database connection is made.
Joe
--
=== Josef Karthauser (joe at tao.org.uk) === http://x2obuilder.com/tao ===
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070125/5a7d8727/attachment.pgp
More information about the Dbix-class
mailing list