in reply to Sqlite DBI $sth->rows

Looks like you are forgetting to call execute after you prepare your handle:
$query_handle->execute($patient_name);
I also recommend turning RaiseError on so that you don't have to explicitly call die and use $dbh->errstr. For example:
use strict; use warnings; use DBI; my $name = shift or die "need patient's name\n"; my $dbh = DBI->connect( 'dbi:SQLite:dbname=foo.dbm',undef,undef, {RaiseError=>1} ); my $sth = $dbh->prepare(' SELECT name FROM patient_data WHERE name = ? '); $sth->execute($name); warn "no match for $name\n" unless $sth->rows;

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)

Replies are listed 'Best First'.
Re: Re: Sqlite DBI $sth->rows
by iburrell (Chaplain) on Oct 22, 2003 at 18:28 UTC
    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;
      ...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).
      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)