in reply to Re: (ar0n) Re: sql connection
in thread sql connection
Not all cursor types can return a RecordCount, including the default ForwardOnly cursor type. Since you aren't explicitly specifying a cursor type, you're getting the default, in which case RecordCount will return -1.
If you truly need the RecordCount, use either a Static or Keyset cursor. However, a Static cursor will load the entire recordset into memory, so you might want to avoid that. A Keyset on the other hand, only loads in the primary keys, and then uses that to cache subsets of the recordset. Of course, if someone adds a row in the meanwhile, it won't be available. Plus, there's extra overhead involved in the multiple roundtrips to update the cache as you navigate the recordset
My guess is that what you really want to know is whether or not the recordset is empty. Try:
That will tell you whether or not it's empty, but can still take advantage of the efficiency of a ForwardOnly cursor.unless ( $rs->{EOF} && $rs->{BOF} ) { ... }
-jehuni
|
|---|