> [EMAIL PROTECTED] 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
> 
This was carried over from a larger script by accident, but in case you 
are curious, I eval in order to capture the connect failure and output 
that error info to a Tk text window. Its not neccessary or wanted to 
die in my Tk app because it connects to multiple databases through 
Radio button selection and doesn't run anything automatically on its 
own.  So if you dig get an error,  go troubleshoot and reconnect... 
Anyway nuff said about that....

> 
> > 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...
> 
I appreciate the response.  I tested selectall_arrayref and as I 
expected, irregardless of the number of rows returned, $results will 
always point to a matrix.  So from what I am seeing, $record->[0] as 
you have written below would have to be written as $record[0]->[0].  At 
this point I've come to conclusion that my requirements are causing 
uneccessary complications.  If it wasn't clear, previously I was 
wanting the data from a sql statement with one row returned to be 
stored into an array of columns, otherwise make it an array of columns 
and rows.....

I'll simply go with a matrix always and be done with it.

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

Reply via email to