Hello there. When I run the attached script the call to txn_do() seems to create a transaction depth of two, so the insert is never actually committed. I see the insert in the MySQL log and the auto increment value of the primary key is increased, but the row of data is never actually inserted.
I have included: ./test.pl ./TestDB.pm ./TestDB/Registration.pm The table schema is in Registration.pm. -- Best wishes, Dave Cardwell. http://davecardwell.co.uk/perl/
#!/usr/bin/perl use strict; use warnings; use TestDB; use Carp qw( carp croak ); my $dbi_dsn = 'dbi:mysql:dbname=test;host=localhost'; my $user = 'DEFINE ME'; my $pass = 'DEFINE ME'; my $schema = TestDB->connect($dbi_dsn, $user, $pass, { AutoCommit => 0, PrintError => 0, RaiseError => 1, ShowErrorStatement => 1, }); carp 'Depth before txn_do: ' . $schema->storage->{transaction_depth}; my $rs; eval { $schema->txn_do(sub{ carp 'Depth before create: ' . $schema->storage->{transaction_depth}; $rs = $schema->resultset('Registration')->create({ name => 'Foo Bar', email => '[EMAIL PROTECTED]', password => [ 'SHA1(?)', 'foobar' ], time => '2007-08-03T09:16:30' }); carp 'Depth after create: ' . $schema->storage->{transaction_depth}; }); # With an explicit commit, it works as expected: # $schema->txn_commit(); }; carp 'Depth after txn_do: ' . $schema->storage->{transaction_depth}; if ( $@ ) { croak "Fail: $@"; } else { # Even when a row of data isn't actually inserted, the primary key is still # auto-incremented. carp 'Success: id #' . $rs->get_column('id'); } # Avoid no explicit disconnect warning - same behaviour with or without. $schema->storage->disconnect(); 1;
package TestDB; use strict; use warnings; use base qw/ DBIx::Class::Schema /; __PACKAGE__->load_classes(); 1;
package TestDB::Registration; use strict; use warnings; use base qw/ DBIx::Class /; # CREATE TABLE `registration` ( # `id` MEDIUMINT( 8) UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT, # `name` VARCHAR( 40) NOT NULL, # `email` VARCHAR( 80) NOT NULL, # `password` CHAR( 40) NOT NULL, # `time` DATETIME NOT NULL, # # PRIMARY KEY ( `id` ) # ) ENGINE=InnoDB DEFAULT CHARSET='utf8'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table('registration'); __PACKAGE__->add_columns( id => { data_type => 'MEDIUMINT', default_value => undef, is_auto_increment => 1, is_nullable => 0, size => 8, extras => { unsigned => 1, }, }, name => { data_type => 'VARCHAR', default_value => '', is_nullable => 0, size => 40, }, email => { data_type => 'VARCHAR', default_value => '', is_nullable => 0, size => 80, }, password => { data_type => 'CHAR', default_value => '', is_nullable => 0, size => 40, }, time => { data_type => 'DATETIME', default_value => '', is_nullable => 0, size => 19, } ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->add_unique_constraint( id => [qw/ id /] ); 1;
_______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/