data67 has asked for the wisdom of the Perl Monks concerning the following question:
BACKGROUND
What i have is a simple search interface for an Oracle 8.1 database. The script takes an
input value (ss#) from the user and process it (returns employee record) through the DBI.
PROBLEM
My problem is on the data handling portion of this program.
Here i am simply searching for let say an employee with his ss#. If that employee with the supplied ss# does not exist
print "employee does not exist". Simple right!
Some people suggested that i rely on error codes returned through $DBI::errstr and use that in my code
to handle conditions, but this i think wont work in oracle because it will ALWAYS return 0 for things like "not found".
And i don't think that using eval{..}and if ($@){..} will be a good idea also. Not to confuse not found with an error. Remeber we are just wanting to handle a not found condition.
look at my while statement. I know the "EMPLOYEE DOES NOT EXIST" part should be outside the while loop.
Searching with this:
Here is my problem:my $quotedSearch = $dbh->quote( $search_for_id ); $SQL = "SELECT * FROM EMPLOYEE WHERE employee_number = $quotedSearch"; eval{ $sth = $dbh->prepare($SQL); }
while (@row = $sth->fetchrow_array) { # Handle null or "undef's" $employee_number = (defined $row[0]) ? $row[0] : ''; $first_name = (defined $row[1]) ? $row[1] : ''; $last_name = (defined $row[2]) ? $row[2] : ''; $email = (defined $row[3]) ? $row[3] : ''; if ($#row > 0) { print "HERE IS ALL YOUR DATA\n"; } else { print "NO DATA FOR RECECORD SEARCHED. DO you WANT TO ADD NEW DATA\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Handling conditions DBI in Oracle 8.1
by jeffa (Bishop) on Jan 15, 2002 at 22:02 UTC | |
by runrig (Abbot) on Jan 15, 2002 at 22:13 UTC | |
|
Re: Handling conditions DBI in Oracle 8.1
by screamingeagle (Curate) on Jan 15, 2002 at 23:06 UTC | |
by data67 (Monk) on Jan 16, 2002 at 00:10 UTC | |
by runrig (Abbot) on Jan 16, 2002 at 00:22 UTC | |
by Rhose (Priest) on Jan 16, 2002 at 20:01 UTC | |
by data67 (Monk) on Jan 17, 2002 at 00:44 UTC |