Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBI query does not fetch all data

Reply
Thread Tools

DBI query does not fetch all data

 
 
Henri Baeyens
Guest
Posts: n/a
 
      08-08-2009
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
 
Reply With Quote
 
 
 
 
kappa
Guest
Posts: n/a
 
      08-09-2009
On 8 Aug., 16:06, Henri Baeyens <(E-Mail Removed)> 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!
 
Reply With Quote
 
 
 
 
Andrew Lee
Guest
Posts: n/a
 
      08-09-2009
On Aug 8, 10:06*am, Henri Baeyens <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ajax image data fetch, javascript IMG data update? Marcus Javascript 2 12-08-2006 04:51 PM
Need some ideas to selectively fetch data via object data source or cache... Siva ASP .Net 1 04-24-2006 08:54 PM
DBI prepare and fetch soup_or_power@yahoo.com Perl Misc 5 08-31-2005 02:38 PM
DBI Mysql storing DBI:binary, trouble with character 26 Jerome Hauss Ruby 0 10-13-2004 03:04 PM
DBI and DBI::Oracle packages configuration ulloa Perl 1 07-22-2004 05:52 PM



Advertisments