//===----------------------------------------------------------------------===// // DuckDB // // duckdb/main/materialized_query_result.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/common/types/column/column_data_collection.hpp" #include "duckdb/common/winapi.hpp" #include "duckdb/main/query_result.hpp" namespace duckdb { class ClientContext; class MaterializedQueryResult : public QueryResult { public: static constexpr const QueryResultType TYPE = QueryResultType::MATERIALIZED_RESULT; public: friend class ClientContext; //! Creates a successful query result with the specified names and types DUCKDB_API MaterializedQueryResult(StatementType statement_type, StatementProperties properties, vector names, unique_ptr collection, ClientProperties client_properties); //! Creates an unsuccessful query result with error condition DUCKDB_API explicit MaterializedQueryResult(PreservedError error); public: //! Fetches a DataChunk from the query result. //! This will consume the result (i.e. the result can only be scanned once with this function) DUCKDB_API unique_ptr Fetch() override; DUCKDB_API unique_ptr FetchRaw() override; //! Converts the QueryResult to a string DUCKDB_API string ToString() override; DUCKDB_API string ToBox(ClientContext &context, const BoxRendererConfig &config) override; //! Gets the (index) value of the (column index) column. //! Note: this is very slow. Scanning over the underlying collection is much faster. DUCKDB_API Value GetValue(idx_t column, idx_t index); template T GetValue(idx_t column, idx_t index) { auto value = GetValue(column, index); return (T)value.GetValue(); } DUCKDB_API idx_t RowCount() const; //! Returns a reference to the underlying column data collection ColumnDataCollection &Collection(); private: unique_ptr collection; //! Row collection, only created if GetValue is called unique_ptr row_collection; //! Scan state for Fetch calls ColumnDataScanState scan_state; bool scan_initialized; }; } // namespace duckdb