Create count and select database queries separately

The previous implementation always created both the count
and the select query.
For readability the property baseQuery has been renamed to select which the
IDO queries must take into account.