ksublondie has asked for the wisdom of the Perl Monks concerning the following question:
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.
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: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;
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?Cannot insert the value NULL into column 'columnname', table 'tablenam +e'; column does not allow nulls. UPDATE fails.
UPDATE: If I make my 2nd do statement to be in the 1st eval:
It works. Something wrong with my eval statements???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;
Back to
Seekers of Perl Wisdom