in reply to DBI Oracle insert not working

In your logging statement you make rname $repository->getName but in your insert you have $scripN instead. So the query that is logged is not the query that is executed.

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:

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;
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.

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
    All fixed, cheers for the help .. It was not using bound parameters which caused the issue ..
      You've drawn the wrong lesson. The issue is that you logged one thing and did another, then got confused when the two didn't match. Now you've rewritten it and were lucky enough to rewrite it correctly. But it wasn't the interpolation technique that you wrote it in which made the difference, it is that you didn't make a mistake this time.