Hi Joe,

DBI does not return an error when no row(s) are found in DB2
because it's not an error, it returns undef instead.
I solved this using the following:

sub SelRecord {

         my $Var  =  $dbh->selectrow_array("$sqlsta");        # Execute sql
statement.
         if  ( my $str = $dbh->errstr() ) {                               # If
error.
            # log the error msg
            return(1);
         }
         else {
             if  ( $Var ) {
                return( 0,$Var );
# record found.
            }
            else { return(1); }
# no record found.
}

Regards,
Paul.

Joe Reganato wrote:

> I have a question/problem about dbi...
>
> I am working with a db2 database ... It appears that on certain
> circumstances, dbi does not
> return a return code and set an error. Specifically when I try to select,
> update or delete a record
> with an invalid key, no return code or return str is set. For example if I
> try to query a record with an invalid key, I should get an rc of 100 (no
> rows found).
>
> I do get an error if I have a hard error i.e. ( database is down, invalid
> sql statement and if I try to insert a record with a duplicate key that is
> referenced by a primary unique index....
>
> I have tried both settings for raise_error and print_error... neither
> setting will have dbi return a code.
>
> I have also tried to eliminate the die clause on the execute statement with
> no effect....
>
> I have also tried to use sth->rows, and that returns a -1 for no rows, or
> when a single row is found...
>
> Could any one help...

Reply via email to