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???