| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/main/stream_query_result.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/common/winapi.hpp" |
| 12 | #include "duckdb/main/query_result.hpp" |
| 13 | |
| 14 | namespace duckdb { |
| 15 | |
| 16 | class ClientContext; |
| 17 | class ClientContextLock; |
| 18 | class Executor; |
| 19 | class MaterializedQueryResult; |
| 20 | class PreparedStatementData; |
| 21 | |
| 22 | class StreamQueryResult : public QueryResult { |
| 23 | friend class ClientContext; |
| 24 | |
| 25 | public: |
| 26 | static constexpr const QueryResultType TYPE = QueryResultType::STREAM_RESULT; |
| 27 | |
| 28 | public: |
| 29 | //! Create a successful StreamQueryResult. StreamQueryResults should always be successful initially (it makes no |
| 30 | //! sense to stream an error). |
| 31 | DUCKDB_API StreamQueryResult(StatementType statement_type, StatementProperties properties, |
| 32 | shared_ptr<ClientContext> context, vector<LogicalType> types, vector<string> names); |
| 33 | DUCKDB_API ~StreamQueryResult() override; |
| 34 | |
| 35 | public: |
| 36 | //! Fetches a DataChunk from the query result. |
| 37 | DUCKDB_API unique_ptr<DataChunk> FetchRaw() override; |
| 38 | //! Converts the QueryResult to a string |
| 39 | DUCKDB_API string ToString() override; |
| 40 | //! Materializes the query result and turns it into a materialized query result |
| 41 | DUCKDB_API unique_ptr<MaterializedQueryResult> Materialize(); |
| 42 | |
| 43 | DUCKDB_API bool IsOpen(); |
| 44 | |
| 45 | //! Closes the StreamQueryResult |
| 46 | DUCKDB_API void Close(); |
| 47 | |
| 48 | //! The client context this StreamQueryResult belongs to |
| 49 | shared_ptr<ClientContext> context; |
| 50 | |
| 51 | private: |
| 52 | unique_ptr<ClientContextLock> LockContext(); |
| 53 | void CheckExecutableInternal(ClientContextLock &lock); |
| 54 | bool IsOpenInternal(ClientContextLock &lock); |
| 55 | }; |
| 56 | |
| 57 | } // namespace duckdb |
| 58 |