Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: DBI confusion

by mje (Curate)
on Jul 23, 2008 at 08:30 UTC ( #699548=note: print w/replies, xml ) Need Help??

in reply to DBI confusion

selectrow_arrayref can obviously find no rows to return in which case it returns undef:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","yyy");my $r = +$h->selectrow_arrayref("select 1 from dual where 1=0");use Data::Dump +er;print Dumper($r);' $VAR1 = undef;

Unfortunately, selectrow_arrayref also returns undef if there is an error:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","xxx",{RaiseErr +or => 0,PrintError => 0});my $r = $h->selectrow_arrayref("select 1 fr +om dualxx");use Data::Dumper;print Dumper($r);' $VAR1 = undef;

the error being "ORA-00942: table or view does not exist". Note I had to turn off RaiseError and PrintError to a) avoid DBI calling die and b) avoid DBI printing the error. To tell the difference between the two you need to set RaiseError and catch the die:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","xxx",{RaiseErr +or => 1,PrintError => 0});my $r; eval{$r = $h->selectrow_arrayref("se +lect 1 from dualxx")};if ($@) { print "Error $@ and DBI err is $DBI:: +err";} else {use Data::Dumper;print Dumper($r);}'

which outputs:

Error DBD::Oracle::db selectrow_arrayref failed: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*>; indicator at char 14 in 'select 1 from <*>dualxx') for Statement "select 1 from dualxx" at -e line 1.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://699548]
[LanX]: see protwin situation
[QM]: Anything like a qualtoo?
[QM]: er, quatloo
[shmem]: ah, silly typo. protein :(

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-08-17 10:11 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (286 votes). Check out past polls.