Hey Perl Monks! I have a piece of code which is running across some data and placing it within an Oracle database. The bug which I have found is that 2 of my SQL statements don't work by executing them in perl, but they do work in Oracle SQL Developer:
my $query = $self->{dbConn}->prepare("INSERT INTO repository(rname +) VALUES('". $repository->getName ."')"); my $affected = $query->execute; $self->{dbConn}->commit; $logger->debug($DBI::errstr || 'no errors found, ' . $affected . ' + affected');
This piece of code places a new repository within the database. This generates a log like:
2009/04/02 11:15:15 DEBUG> ResultSQL.pm:62 ResultSQL::prvInsertRepo - +Reporting repository 2009/04/02 11:15:15 DEBUG> ResultSQL.pm:65 ResultSQL::prvInsertRepo - +INSERT INTO repository(rname) VALUES('testSQL') 2009/04/02 11:15:15 DEBUG> ResultSQL.pm:69 ResultSQL::prvInsertRepo - +no errors found, 1 affected
This next example of code is where the bug is:
$logger->debug("INSERT INTO script(repoid, sname) SELECT repoid, '" +. $scriptN . "' as sname FROM repository WHERE rname='" . $repository +->getName . "'"); my $query = $self->{dbConn}->prepare("INSERT INTO script(repoi +d, sname) SELECT repoid, '" . $scriptN . "' as sname FROM repository +WHERE rname='" . $scriptN . "'"); my $affected = $query->execute; $self->{dbConn}->commit; $logger->debug($DBI::errstr || 'no errors found, ' . $affected + . ' affected');
This generates this log:
2009/04/02 11:15:15 DEBUG> ResultSQL.pm:78 ResultSQL::prvInsertScripts + - Reporting scripts 2009/04/02 11:15:15 DEBUG> ResultSQL.pm:81 ResultSQL::prvInsertScripts + - INSERT INTO script(repoid, sname) SELECT repoid, 'tableName' as sn +ame FROM repository WHERE rname='testSQL' 2009/04/02 11:15:15 DEBUG> ResultSQL.pm:85 ResultSQL::prvInsertScripts + - no errors found, 0E0 affected
There is another method which gets called after this, but it pretty much does the same job but if a different set of data. When I check the database out I would have an entry in the repository table, but nothing else. As I said before, if I take the SQL from my log, paste it into SQL Developer, it will execute as expected.. Any ideas? I am totally stuck.. Cheers in advance ..

In reply to 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.