Closed Bilge closed 3 years ago
The row count cannot be known for all queries and this method will be removed from PgSqlResult
in the next version. The new Result
object will have getRowCount()
, but it may return null
if the number of rows is unknown.
If it's a results set, to my knowledge, the row count can always be known. If it is not, then it's an entirely different object: PgSqlCommandResult
. In any case, I will hold off making a PR if you are going to address this issue directly. Although, if the new version is not backwards-compatible, I still think it is worth addressing the issue in this major version.
Unbuffered result sets do not provide a total row count, so that's why the method is missing from the pool result set. I potentially could add numRows()
to PooledResultSet
in this version, but it would sometimes return null
if the pooled result set is unbuffered.
See the streams
branch for the upcoming version in sql
, sql-common
, and this repo.
What determines whether a results set is "buffered"?
The ext-pq driver is capable of returning unbuffered results. Usually if a query is more than a few rows it is not buffered, but sent in chunks instead. PqUnbufferedResultSet
does not have a numRows()
method because of this.
One of the most useful things to know when performing a query is how many results are in the results set. This information is provided by the driver and exposed by a public method in this library, but by an object that is inaccessible to the consumer.
PgSqlResultSet
exposes the methodnumRows()
, butPgSqlResultSet
is wrapped byPooledResultSet
which is what the consumer actually receives and which does not provided any public access to the underlyingPgSqlResultSet
. Due to this, the row count is inaccessible to the consumer.Also, and this is a side issue, even if it were possible to access
numRows()
viaPooledResultSet
, the library only declares interfaces, and the method is not present on the generic SQL interface so declared. The consumer would have to know the underlying object's exact type and override the type system to access it.