rowValues method
Streams all rows from the data set as lists.
The stream ends when all rows from the result set have been
fetched from the database and streamed to the calling code.
The rows are fetched in batches of size chunkSize,
to reduce the number of messages passed between the main
and worker isolates (the higher chunkSize, the less
messages need to be exchanged between the isolates,
but the larger each of those messages is).
Example:
await q.openCursor(
sql: "select * from DEPARTMENT "
"where DEPT_NO = ?",
parameters: ["180"], // a single string parameter
);
await for (var row in q.rowValues()) {
print(row[0]); // print the value from the first column
}
await q.close();
Implementation
Stream<List<dynamic>> rowValues({int chunkSize = 10}) async* {
if (_toWorker == null) {
throw FbClientException(
"No active query associated with this query object",
);
}
if (chunkSize <= 0) {
throw FbClientException("Invalid chunk size: $chunkSize");
}
while (true) {
final msg = await _db?._askWorker(FbDbControlOp.fetchMany, [
FbRowFormat.asList,
chunkSize,
], _toWorker);
_throwIfErrorResponse(msg);
final r = msg as FbDbResponse;
if (r.data.isEmpty || r.data[0] == null) {
return; // no more sets of rows
}
final rows = r.data[0] as List<List<dynamic>>;
for (final r in rows) {
yield r;
}
if (rows.length < chunkSize) {
break; // that was the last batch
}
}
}