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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    667
    Juha Laiho
    Jul 22, 2004
  2. Leon
    Replies:
    5
    Views:
    1,002
  3. Siva
    Replies:
    1
    Views:
    1,436
    Jeff Dillon
    Apr 24, 2006
  4. Bernard Lebel
    Replies:
    7
    Views:
    442
    Mark Hertel
    Jan 26, 2006
  5. zxo102
    Replies:
    5
    Views:
    616
    Dennis Lee Bieber
    Mar 23, 2006
  6. Jerome Hauss
    Replies:
    0
    Views:
    303
    Jerome Hauss
    Oct 13, 2004
  7. DBI prepare and fetch

    , Aug 30, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    236
  8. Marcus
    Replies:
    2
    Views:
    266
    Peter Michaux
    Dec 8, 2006
Loading...