Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

perl dbi and RaiseError handling - is this a situations which won't raise an error?

2 views
Skip to first unread message

lvirden

unread,
Nov 25, 2008, 9:13:40 AM11/25/08
to
In a perl script I have:

:
some setup
:
# logon to Oracle
$oraProdDBH = DBI->connect("dbi:Oracle:", $user_name, $password)
or die "Failed to connect to $DBI:errstr\n";

$oraProdDBH->{RaiseError} = 1;
:more stuff
:
and subsequent statement handles created and invoked. When the insert
sql is invoked, the data gets into the tables. Also, if some of the
input data doesn't match oracle's description, an error is raised,
just as I expect.

Likewise, when deletes occur, the data is deleted.

The question comes in with the update statements. The update statement
says:

$oraProdDBH->do
(
"UPDATE CSI_SECURITY SET " .
"LAST_NAME=" . $oraProdDBH->quote ($employee->[1]) . ",
" .
"FIRST_NAME=" . $oraProdDBH->quote ($employee->[2]) . ",
" .
"INITIALS=" . $oraProdDBH->quote ($employee->[3]) . ", " .
"PREFERRED_NAME=" . $oraProdDBH->quote ($employee->[4]) .
", " .
"DEPT_NO=" . $employee->[5] . ", " .
"EMP_STATUS=" . $oraProdDBH->quote ($employee->[6]) . ",
" .
"REC_MOD_DATE=SYSDATE " .
"WHERE " .
"PERSON_ID=" . $employee->[0]
);

Now, when the PERSON_ID matches, the update occurs. When the
PERSON_ID is not found, however, an error isn't raised.

Should an error be raised? If not, then I guess I need to do a select
first to see if the item exists? Or is there something I can check in
DBI that will tell me that the operation didn't work?

Thank you for your help.

Malcolm Dew-Jones

unread,
Dec 2, 2008, 4:16:38 PM12/2/08
to
lvirden (lvi...@gmail.com) wrote:
: In a perl script I have:

: :
: The question comes in with the update statements. The update statement
: says:

: $oraProdDBH->do
: (
: "UPDATE CSI_SECURITY SET " .

(snip)


: Now, when the PERSON_ID matches, the update occurs. When the


: PERSON_ID is not found, however, an error isn't raised.

No, because no error occurred. The update updated the rows that matched.
It is not an error for no rows to match.


: Should an error be raised? If not, then I guess I need to do a select


: first to see if the item exists? Or is there something I can check in
: DBI that will tell me that the operation didn't work?


Copied from "perldoc DBI", you can use something like

$rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1");

0 new messages