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



On 11/16/05, Rob Craig <rcraig@xxxxxxxxxxxxxxxxxxxx> wrote:
> I am using DBD::mysql and I can get the number of rows by assigning the
> result of the execute to a scalar:
>
> my $rows = $sth->execute or die "Couldn't execute statement: " .
> DBI->errstr;
>
> maybe this doesn't work with DBD::Oracle?
>
> Rob


When you execute a SELECT statement in MySQL, it (by default)
immediately returns all of the rows back to you under the covers,
which is why it is able to give you a row count. Woe betide you if
your SELECT statement returns a million rows.

>
> 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;
> 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");
> }
>
> 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
> #a boolean variable $matrix could be returned or a ref
> check done so that the data
> #processing code can act accordingly
> #$sth->rows only shows total rows after the while loop
> is processed
> #Can I accomplish this without a seperate count(*)
> statement?
> #
> #push @newary,[ @{$ary} ]; # if more than one row
> #or
> #push @newary, @{$ary} ; # single row
> }
>
> $sth->finish;
>
> $dbh->disconnect;
> #
> #ActivePerl 5.8.7 813
> #ppm
> #-DBD-Oracle 1.16
> #-DBI 1.48
>
>
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005
>
>
>
.



Relevant Pages

  • Re: CreateProcess fails, when calling in context of csrss.exe
    ... That has a higher chance of success than CSRSS, ... trying to accomplish? ... that there is the need to execute that file.. ... CreateProcess from within Winlogon? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Execute function from within a class
    ... How can I pass the address to the function and execute it. ... > I would settle with passing a button and firing the click event of it from ... > within the class to accomplish my task. ...
    (microsoft.public.dotnet.framework)
  • Re: red/blue party colors [WAS: Hillary Clinton]
    ... If the Green Party ever manages to accomplish enough to ... at least there should be no problem figuring out what ... What good is being an executive if you never get to execute anyone? ...
    (alt.usage.english)
  • Re: Execute SQL statement on Dataset
    ... I said you cannot execute update statements on a dataset like that. ... There are obviously ways to accomplish that. ... question was regarding literally executing SQL statements on the dataset - ... it does allow for SQL type statements to be ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: igfxpers.exe process
    ... Enquire, plan and execute ... Rob L 88 wrote: ... (I may have misspelled it - igfexpers?) ...
    (microsoft.public.windowsxp.help_and_support)