streamQueryBuffer method

Stream<ParsedRowBuffer> streamQueryBuffer(
  1. int connectionId,
  2. String sql, {
  3. int chunkSize = 1000,
  4. bool lazyStrings = false,
})
inherited

Legacy buffer-mode streaming via odbc_stream_start. Materialises the full result in native memory before yielding a single parsed chunk. Prefer streamQuery or streamQueryBatched for large result sets.

Implementation

Stream<ParsedRowBuffer> streamQueryBuffer(
  int connectionId,
  String sql, {
  int chunkSize = 1000,
  bool lazyStrings = false,
}) async* {
  final streamId =
      _native.streamStart(connectionId, sql, chunkSize: chunkSize);

  if (streamId == 0) {
    throw Exception('Failed to start stream: ${_native.getError()}');
  }

  final buffer = BytesBuilder(copy: false);
  try {
    while (true) {
      final result = _native.streamFetch(streamId);

      if (!result.success) {
        throw Exception('Stream fetch failed: ${_native.getError()}');
      }

      final data = result.data;
      if (data == null || data.isEmpty) {
        break;
      }
      buffer.add(data);

      if (!result.hasMore) {
        break;
      }
    }
    if (buffer.length > 0) {
      final parsed = decodeBatchedStreamFrame(
        buffer.toBytes(),
        lazyStrings: lazyStrings,
      );
      yield parsed;
    }
  } finally {
    _native.streamClose(streamId);
  }
}