Re: anyway to determine # rows before fetch loop ends and without seperate count(*)
- From: mlists@xxxxxxxxxxxxxxx (JupiterHost.Net)
- Date: Wed, 16 Nov 2005 16:25:48 -0600
listmail@xxxxxxxxxxxx wrote:
#Here's an example which shows what I am trying to accomplish. If I can determine the number of rows before pushing the data, this can simply things for #me when processing the data throught my scripts. #
use warnings;
use strict;
Good good :)
use DBI; use DBD::Oracle;
my $sql=q{ select name, location from mytable };
my $dbh;
eval { $dbh = DBI->connect("dbi:Oracle:MYDB", 'dbuser', 'dbpass', { RaiseError => 1, AutoCommit => 0, ora_session_mode => 0 } ); };
if ( $@ ) { outprint('end',"$DBI::errstr\n"); }
Hmm, perhaps the oracle specific stuff needs it but why are you evaling that?
my $dbh = DBI->connect(@DBI_CONNECT_ARGS) or outprint('end', $DBI::errstr); # assumign its die()ing or exit()ing
my $sth=$dbh->prepare($sql) or die "Couldn't prepare statement: " . DBI-
errstr;
$sth->execute or die "Couldn't execute statement: " . DBI->errstr;
my $ary;
while ($ary = $sth->fetchrow_array()) {
#I need to determine number of rows as this will affect whether a matrix is used or not
Also very convoluted, all of that can be done with:
my $results = $dbh->selectall_arrayref($sql); # if you only want to process a certain amount just LIMIT in your $sql...
my $count = @{ $results };$dbh->disconnect;
if($count < 1000) { # or whatever you wanted teh count for...
for my $record(@{ $results }) {
# now use the data:
# $record->[0]
# $record->[1]
}
}
.- References:
- Prev by Date: RE: anyway to determine # rows before fetch loop ends and without seperate count(*)
- Next by Date: problem with DBI oracle access with activstate perl
- Previous by thread: anyway to determine # rows before fetch loop ends and without seperate count(*)
- Next by thread: Re: anyway to determine # rows before fetch loop ends and without seperate count(*)
- Index(es):
Relevant Pages
|