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.


In reply to Re: DBI Oracle insert not working by tilly
in thread DBI Oracle insert not working by smoky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.