ksublondie has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL through perl is giving error
by roboticus (Chancellor) on Aug 31, 2011 at 21:44 UTC | |
by ksublondie (Friar) on Aug 31, 2011 at 21:50 UTC | |
|
Re: SQL through perl is giving error
by ikegami (Patriarch) on Aug 31, 2011 at 21:26 UTC | |
|
Re: SQL through perl is giving error
by choroba (Cardinal) on Aug 31, 2011 at 22:02 UTC | |
by ksublondie (Friar) on Aug 31, 2011 at 23:29 UTC | |
by Anonymous Monk on Sep 01, 2011 at 03:17 UTC | |
by remiah (Hermit) on Sep 01, 2011 at 05:56 UTC |