in reply to Re: Creating Dynamic SQL statements using arrays
in thread Creating Dynamic SQL statements using arrays

Regarding this point:
Having retrieved the values I now need to display the results. The code I am using requires foreknowledge of the amount of results to be outtputted. However I don't know how many are to be outputted until run time.

Is it the number of rows you need to anticipate? or the number of columns? or both? If the listing follows from the kind of query you asked about earlier, you already have the array of columns that you're selecting, so that can be used again for printing.

To know the number of rows in advance of printing them out, you could try one of the "fetchall" or "selectall" DBI methods; these return an array ref which you can then check with "scalar( @$array_ref )" to get the number of rows returned. Or, if you're worried that this might put too much overhead/memory-load on your system if the return on the query is really big, and you really want to know how many rows you're going to get before you print them, do a "pre-query" that starts with "select count(some_field) where $where_clause"... But in my own experience (on solaris/oracle) there seems to be less time/trouble in using a "fetchall" than in doing a big query two times (though I have never tested this rigorously).

  • Comment on Re: Re: Creating Dynamic SQL statements using arrays