1#include "duckdb/main/capi/capi_internal.hpp"
2#include "duckdb/common/types/timestamp.hpp"
3#include "duckdb/common/allocator.hpp"
4
5duckdb_data_chunk duckdb_stream_fetch_chunk(duckdb_result result) {
6 if (!result.internal_data) {
7 return nullptr;
8 }
9 auto &result_data = *((duckdb::DuckDBResultData *)result.internal_data);
10 if (result_data.result_set_type == duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED) {
11 return nullptr;
12 }
13 if (result_data.result->type != duckdb::QueryResultType::STREAM_RESULT) {
14 // We can only fetch from a StreamQueryResult
15 return nullptr;
16 }
17 result_data.result_set_type = duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_STREAMING;
18 auto &streaming = (duckdb::StreamQueryResult &)*result_data.result;
19 if (!streaming.IsOpen()) {
20 return nullptr;
21 }
22 // FetchRaw ? Do we care about flattening them?
23 auto chunk = streaming.Fetch();
24 return reinterpret_cast<duckdb_data_chunk>(chunk.release());
25}
26