in reply to Re: Sqlite DBI $sth->rows
in thread Sqlite DBI $sth->rows

Your suggestion about using RaiseError is good. The only snag is that RaiseError does not apply to the connect call that creates the database handle. The success of the connect needs to be checked explicitly.
my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db',undef,undef, { RaiseError=>1 } ) or die $DBI::errstr;

Replies are listed 'Best First'.
Re: Re: Re: Sqlite DBI $sth->rows
by runrig (Abbot) on Oct 22, 2003 at 19:00 UTC
    ...RaiseError does not apply to the connect call...

    Yes, it does apply. If it doesn't, then it's a bug in the DBD. So you don't need an 'or die ...' on the connect when you use RaiseError

      > ...RaiseError does not apply to the connect call...

      Correct!

      >> Yes, it does apply. If it doesn't, then it's a bug in the DBD. So you don't need an 'or die ...' on the connect when you use RaiseError

      Incorrect. If the connect fails, no $dbh is returned. With no $dbh, the fact that $dbh->{RaiseError} is set to 1 is irrelevant (and unknowable).
        With no $dbh, the fact that $dbh->{RaiseError} is set to 1 is irrelevant (and unknowable).

        And why wouldn't DBI 'know' that you've set RaiseError to 1?

        And see jeffa's reply below.

3Re: Sqlite DBI $sth->rows
by jeffa (Bishop) on Oct 22, 2003 at 20:48 UTC
    The success of the connect most certainly does not need to be checked explicitly, that is, by both setting RaiseError and calling die yourself - DBI.pm does it for you:
    
    DBI.pm (version 1.38)
    358: sub connect {
    ...
    416: unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $attr)) {
            my $msg = "$class->connect($dsn) failed: ".$drh->errstr;
            if (ref $attr) {
                Carp::croak($msg) if $attr->{RaiseError};
                Carp::carp ($msg) if $attr->{PrintError};
            }
            DBI->trace_msg("       $msg\n");
            $! = 0; # for the daft people who do DBI->connect(...) || die "$!";
            return undef;
        }
    ...
    

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)