>>>>> "Dawa" == Dawa Lama <[EMAIL PROTECTED]> writes:

Dawa> What would PostgreSQL return for empty table or when the SELECT
Dawa> doesn't find any item specified in the condition.

I'm unfamiliar with the "fetchrow" method.

My preferred method is to use "fetch", which will return an array
reference so long as there are rows to retrieve, or an undef (thus
false) value when it is done:

| my $sth = $dbh->prepare("...");
| $sth->execute();
| my $n_rows = 0;
| while (my $cur = $sth->fetch())
| {
|    $n_rows++;
|    # ...
| }
| $sth->finish();

If you actually want to load an array with all the values returned in
each row, you want the "fetchrow_array" method, which has this
important clue in its documentation:

> If there are no more rows or an error occurs then fetchrow_array
> returns an empty list. You should check $sth->err afterwards (or use
> the RaiseError attribute) to discover if the empty list returned was
> due to an error.

So, our main loop would be:

| while (my @row = $sth->fetchrow_array())
| {
|    $n_rows++;
|    # ...
| }

This will quit as soon as it has an empty list; if the query doesn't
generate any rows at all, it will return an empty list immediately.

If you want to grab all values from one column, or all values from all
rows, investigate the "selectcol_arrayref" and "selectall_arrayref"
methods in "perldoc DBI".

t.


Reply via email to