> > Hi, > > My code just fails to insert the records to the database. > Anybody can figure out the problem? Thanks in advance. > Here is the snippet: > ######################################################### > my $dbn="newgene"; > my $dbh=DBI->connect("dbi:ODBC:$dbn",'','')|| die "$DBI::errstr\n"; > my @records = ( > ["La", "M", "1" ], > ["Tim Bunce","M","2" ] > ); > > my $sql = qq{ INSERT INTO clients VALUES ( ?, ?, ? ) }; > my $sth = $dbh->prepare( $sql )|| die "$DBI::errstr\n"; > > for( @records ) { > eval { > $sth->bind_param( 1, @$_->[0], SQL_VARCHAR ); > $sth->bind_param( 2, @$_->[1], SQL_VARCHAR ); > $sth->bind_param( 3, @$_->[2], SQL_INTEGER ); > $sth->execute() || die "$DBI::errstr\n"; > $dbh->commit() || die "$DBI::errstr\n";
Since autocommit is enabled, it's actually committing after each insert. It may be the problem. In your script below, since you are catching $@, print $@... > }; > > if( $@ ) { > warn "Database error: $DBI::errstr\n"; > $dbh->rollback(); #just die if rollback is failing > } > } > > $sth->finish(); > $dbh->disconnect(); > ######################################################### > where column 3 is the primary key of table clients. Error message: > "Database error: > rollback ineffective with AutoCommit enabled at myprogram.pl line 55." > Jeff