Re: Affected Rows

From: Amonotod (amonotod_at_charter.net)
Date: 01/24/05


To: <dbi-users@perl.org>
Date: Mon, 24 Jan 2005 14:03:18 -0600


> From: Hernan Arredondo <hernan.arredondo@gmail.com>
> Date: 2005/01/24 Mon PM 12:41:56 CST

> of rows affected by a select statement, use the "$var = $st->rows" but
> it no works in select statements, the other way is making a while
> statement to get the result in an array, but I think is a easy way to
> do it , anyone knows other easy method ?
rows

FROM THE DOCS!
<snip>
  $rv = $sth->rows;

    Returns the number of rows affected by the last row affecting command, or -1 if the number of rows is not known or not available.

    Generally, you can only rely on a row count after a non-SELECT execute (for some specific operations like UPDATE and DELETE), or after fetching all the rows of a SELECT statement.

    For SELECT statements, it is generally not possible to know how many rows will be returned except by fetching them all. Some drivers will return the number of rows the application has fetched so far, but others may return -1 until all rows have been fetched. So use of the rows method or $DBI::rows with SELECT statements is not recommended.

    One alternative method to get a row count for a SELECT is to execute a ``SELECT COUNT(*) FROM ...'' SQL statement with the same ``...'' as your query and then fetch the row count from that.

</snip>

> Regards
>
> Hernan Dario Arredondo

HTH,
amonotod

--
    `\|||/         amonotod@    | sun|perl|windows
      (@@)         charter.net  | sysadmin|dba
  ooO_(_)_Ooo____________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Relevant Pages

  • Re: Array and resize
    ... > Thanks for the reply Bob, ... > Excel worksheet. ... >> You are not creating a 2D array, but an array containing arrays, and you ... >> HTH ...
    (microsoft.public.excel.programming)
  • Re: Does MySql have any built in search functionality
    ... >> mainContent ORDER BY number of matches per entry DESC ... > HTH ... available you could read the query result into an array and then use PHP ...
    (comp.lang.php)
  • Re: Multiple additions
    ... range, starting at A4, and by multiplying by the range, it extracts the ... SUMPRODUCT sums that array. ... >> HTH, ...
    (microsoft.public.excel.misc)
  • Re: Combo Box "Selection" Get / Let
    ... keepITcool ... the list is fed in as an array on form loading. ... > programatically based on other choices user makes on the form. ...
    (microsoft.public.excel.programming)
  • Re: This should be easy...
    ... I am not sure what you mean by the extra columns. ... HTH ... (remove nothere from the email address if mailing direct) ... > that should not be counted in my equation, but if you use an array ...
    (microsoft.public.excel.worksheet.functions)