Re: anyway to determine # rows before fetch loop ends and without seperate count(*)





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]
    }
}
.



Relevant Pages

  • Re: Windows Internet Explorer 7 beta - Security Warnings
    ... .vbs/.bat scripts and programs from mapped network drives. ... when I use the UNC path, I m not getting these warnings (Ex. ... running a script from the command line, I also get a security warning. ... this is a settings change rather than a "problem". ...
    (microsoft.public.security)
  • Re: [PATCH -mm] sys_semctl gcc 4.1 warning fix
    ... with merge into git for some parts) that does that following: ... not everyone has your scripts or the time to use them. ... warnings of others. ... even starting with diff between the trees works fairly well. ...
    (Linux-Kernel)
  • Re: DocumentHTML ?
    ... Any hints, please? ... to set your security settings to a low and possibly unsafe level. ... But of course I use warnings! ... You didn't see it in my snippet because I always run scripts ...
    (comp.lang.perl.misc)
  • Re: use warnings and -w behaviour
    ... the scripts run just fine but when I switch to the 'use warnings' ... The error itself doesn't look like a Perl message, ... the shell on the Solaris server or your local cmd that emits it. ...
    (comp.lang.perl.misc)