Package com.couchbase.lite
Class ResultSet
java.lang.Object
com.couchbase.lite.ResultSet
- All Implemented Interfaces:
AutoCloseable
,Iterable<Result>
The representation of a query result. The result set is an iterator over
Result
objects.
Note: This object retains the Results it contains: closing it will
free the Results, too. Referencing a Result after closing the ResultSet
that contains it will cause a crash.
This code, for instance will fail. DO NOT DO THIS:
final List<Result> results;
try (ResultSet rs = QueryBuilder.select(SelectResult.expression(Meta.id).as("id"))
.from(DataSource.collection(someCollectin))
.execute()) { results = rs.allResults(); }
catch (CouchbaseLiteException err) {
throw new RuntimeException("Failed querying docs in collection: " + someCollection, err);
}
final List<String> docs = new ArrayList<>();
for (Result result: results) { docs.addt(result.getString("id")); } // SIGSEGV!!!
-
Method Details
-
next
Move the cursor forward one row from its current row position.Caution:
next()
,iterator()
anditerator()
method share same data structure. They cannot be used together.Caution: When a ResultSet is obtained from a QueryChangeListener and the QueryChangeListener is removed from Query, the ResultSet will be freed and this method will return null.
- Returns:
- the Result after moving the cursor forward. Returns
null
value if there are no more rows, or ResultSet is freed already.
-
allResults
Return a List of all Results.Caution:
next()
,allResults()
anditerator()
method share same data structure. They cannot be used together.- Returns:
- List of Results
-
iterator
Return Iterator of Results.Caution:
next()
,allResults()
anditerator()
method share same data structure. They cannot be used together. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
finalize
-