Hi all,
This thing has been bothering me for a little while so here it is..
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:
my $quotedSearch = $dbh->quote( $search_for_id );
$SQL = "SELECT * FROM EMPLOYEE WHERE employee_number = $quotedSearch";
eval{
$sth = $dbh->prepare($SQL);
}
Here is my
problem:
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";
}
}
As always, any suggestions will go a long ways....