in reply to Empty Hash?

For many databases, $sth->rows() returns how many lines are returned. If the DB can't do that, -1 is returned instead; then check the documentation of the DBD (e.g. perldoc DBD::mysql) if there is a special attribute or method which either gives you the ammount of rows or tells you that no more rows are available. If there is a method that tells you that no more results are available (e.g. with sybase), just check it before you fetch the data (e.g. before the while-loop) to find out if there is no data returned

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Replies are listed 'Best First'.
Re^2: Empty Hash?
by jZed (Prior) on Dec 31, 2004 at 16:54 UTC
    From the DBI docs:

    "use of the rows method or $DBI::rows with SELECT statements is not recommended"

      As soon as I read that I wanted to know why. So I looked it up. Here is a bit more context:
      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.
Re^2: Empty Hash?
by mpeppler (Vicar) on Jan 03, 2005 at 19:11 UTC
    If there is a method that tells you that no more results are available (e.g. with sybase), just check it before you fetch the data (e.g. before the while-loop) to find out if there is no data returned
    Actually that's not quite right.

    DBD::Sybase's syb_more_results attribute will be TRUE until the first fetch been called, even if no rows are returned by a query - so you can't use that attribute (or DBI's upcoming mre_results() method) to check for zero length result sets.

    Michael