Make queryByIndex() working with dbms.

For data sources with inconsistent row numbers, queryByIndex should not set a resultindex. The resultindex is read from the row number of the result set which is likely to have a single row when working with databases. Only shape files are considered to have consistent row numbers and may be read form the result cache. (#4076 #4926)