in reply to DBI Oracle insert not working
A second error you make is making several calls to DBI without checking for errors and then only checking $DBI::errstr at the end. Unfortunately that variable is reset when entering most API calls, so an error in your prepare or execute will no longer be available to see after your commit. This is one reason that I prefer setting RaiseError=>1 on my connect calls.
To avoid these problems in the future you could use the following coding pattern:
In this sample I have not used bind parameters. Bind parameters are important if you do not absolutely trust your incoming data. There are also performance benefits. However when you use them it is slightly easier to log one thing and do another, which is a mistake you just made.my $sql = qq{ INSERT INTO script (repoid, sname) SELECT repoid, '$scriptN' as sname FROM repository WHERE rname = '} . $repository->getName . qq{' }; $logger->debug($sql); my $query = $self->{dbConn}->prepare($sql) or die "Can't prepare: $DBI::errstr"; my $affected = $query->execute() or die "Can't execute: $DBI::errstr"; $self->{dbConn}->commit;
So the lesson I chose to focus on is the value of not repeating yourself. Even if you're just saying it twice, say it once, stick it in a variable, and then use that variable twice. This guarantees that the statement logged is the statement actually prepared.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI Oracle insert not working
by smoky (Novice) on Apr 02, 2009 at 12:32 UTC | |
by tilly (Archbishop) on Apr 02, 2009 at 12:56 UTC |