DBI query does not fetch all data

Discussion in 'Perl Misc' started by Henri Baeyens, Aug 8, 2009.

  1. Hello,

    I'm using DBI and an ODBC driver to get data from an Access database. The
    query is executed but only part of the data is fetched. I know that the
    database contains over 1500 rows. My query returns only 28 rows.

    use DBI;
    use strict;
    use warnings;


    my $dbh = DBI->connect('dbi:ODBC:boutique', {RaiseError => 1} );
    my $query;
    my $table = "articles";
    my @row_array;

    $query = $dbh->prepare("SELECT * FROM $table");
    $query->execute;

    while (@row_array=$query->fetchrow_array) {
    foreach my $item (@row_array){
    if ($item eq ""){
    print qq~ NULL |~;
    } else {
    print qq~ $item |~;
    }
    }
    }
    my $numrows = $query->rows;
    print qq~Number of rows fetched: $numrows~;

    etc...


    There's also the fact that columns are not fetched in the same order as
    they are in the source database, but that's a minor problem.


    I can't figure it out. Anything I am missing?

    H

    www.henribaeyens.com
     
    Henri Baeyens, Aug 8, 2009
    #1
    1. Advertising

  2. Henri Baeyens

    kappa Guest

    On 8 Aug., 16:06, Henri Baeyens <> wrote:
    > Hello,
    >
    > I'm using DBI and an ODBC driver to get data from an Access database. The
    > query is executed but only part of the data is fetched. I know that the
    > database contains over 1500 rows. My query returns only 28 rows.
    >
    > use DBI;
    > use strict;
    > use warnings;
    >
    > my $dbh = DBI->connect('dbi:ODBC:boutique', {RaiseError => 1} );
    > my $query;
    > my $table = "articles";
    > my @row_array;
    >
    > $query = $dbh->prepare("SELECT * FROM $table");
    > $query->execute;
    >
    > while (@row_array=$query->fetchrow_array) {
    >    foreach my $item (@row_array){
    >       if ($item eq ""){
    >         print qq~ NULL |~;
    >       } else {
    >         print qq~ $item |~;
    >       }
    >    }}
    >
    > my $numrows = $query->rows;
    > print qq~Number of rows fetched: $numrows~;
    >
    > etc...
    >
    > There's also the fact that columns are not fetched in the same order as
    > they are in the source database, but that's a minor problem.
    >
    > I can't figure it out. Anything I am missing?
    >
    > H
    >
    > www.henribaeyens.com


    try "select count(*) from table" to be sure!
     
    kappa, Aug 9, 2009
    #2
    1. Advertising

  3. Henri Baeyens

    Andrew Lee Guest

    On Aug 8, 10:06 am, Henri Baeyens <> wrote:
    > Hello,
    >


    >
    > $query = $dbh->prepare("SELECT * FROM $table");
    > $query->execute;



    ....

    A point of good practice:
    if ( $dbh->errstr) { die $dbh->errstr; }

    Just as with file or network I/O, don't assume a database command
    worked.
     
    Andrew Lee, Aug 9, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ulloa
    Replies:
    1
    Views:
    527
    Juha Laiho
    Jul 22, 2004
  2. zxo102
    Replies:
    5
    Views:
    443
    Dennis Lee Bieber
    Mar 23, 2006
  3. Jerome Hauss
    Replies:
    0
    Views:
    172
    Jerome Hauss
    Oct 13, 2004
  4. Asby

    Mason, DBI, and DBI::Pg

    Asby, Jul 24, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    177
  5. DBI prepare and fetch

    , Aug 30, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    138
Loading...

Share This Page