I'm stumped and need help.

I am trying to execute a MS sql command through a perl cgi interface that works from the management console, but dies through my script.

my $inventoryInsert=...; my $inventoryUpdate=...; my $statement=...; warn $inventoryUpdate.$statement."\n"; eval{ $db->do($inventoryUpdate.$statement); }; if ($@){ warn "Can't update. Trying insert.\n\n$inventoryInsert$statement"; eval{ $db->do($inventoryInsert.$statement); }; if ($@){ warn "Aborted because $@"; $db->rollback; return 0; } } $db->commit;
For the transactions that are failing on the update statement and running the insert statement instead, I'm getting the following error relating to the $statement command:
Cannot insert the value NULL into column 'columnname', table 'tablenam +e'; column does not allow nulls. UPDATE fails.
BUT if I directly copy/paste the exact generated sql command from the management console query window, it succeeds w/no errors. Why is one generating an error and the other is fine?

UPDATE: If I make my 2nd do statement to be in the 1st eval:

eval{ $db->do($inventoryInsert.$statement); # $db->do($inventoryUpdate.$statement); }; if ($@){ warn "Can't update. Trying insert.\n\n$inventoryInsert$statement"; eval{ $db->do($inventoryInsert.$statement); }; if ($@){ warn "Aborted because $@"; $db->rollback; return 0; } } $db->commit;
It works. Something wrong with my eval statements???

In reply to SQL through perl is giving error by ksublondie

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.