On Fri, 26 Apr 2002 14:02:15 -0400 "Shao, Chunning" <[EMAIL PROTECTED]> wrote:

> I need to plot a result set from DBI.  Before I can do that, I need to
> know how many rows are returned, so I can set up my x, y axis right.
> 
> I am doing
> #######################################################
> $csr = $dbh->prepare($sql);
> $csr->execute();
> 
> #get the number that how many rows returned
> my $number_rows = 0;

my @allrows;

> while (my @rows = $csr->fetchrow_array )
> {
# fetchrow_array fetches one row, so @row might be a better name

push @allrows, [ @row ];

##>         $number_rows +=1;
> }

$number_rows = @allrows;

> Set my x,y axis accordingly............
> 
> #begin to plot the data
> my ($x_definition,$y_definition);
##> while (my @row = $csr->fetchrow_array )
foreach my $row_ref ( @allrows ) 
> {
>         $counter = 0;

foreach my $data ( @{$row_ref} )

##>         foreach my $data (@row)
>           Plot the data
> }
> ########################################################
> but I got an error 
> 281
> DBD::Oracle::st fetchrow_array failed: ERROR no statement executing
> (perhaps you need to call execute first) at ./test.pl line 162.
> 
> Do I have to make a second db call, or there is better way of doing it?

There is no general way to rewind a SQL query.  If the result set is small
enough, just save all of it in an array, get the number of rows from the
array size, and use the array for the plot.

If the result set may be too big, abort when you see too many rows.
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.htm
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Reply via email to