1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/main/materialized_query_result.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/types/chunk_collection.hpp"
12#include "duckdb/main/query_result.hpp"
13
14namespace duckdb {
15
16class MaterializedQueryResult : public QueryResult {
17public:
18 //! Creates an empty successful query result
19 MaterializedQueryResult(StatementType statement_type);
20 //! Creates a successful query result with the specified names and types
21 MaterializedQueryResult(StatementType statement_type, vector<SQLType> sql_types, vector<TypeId> types,
22 vector<string> names);
23 //! Creates an unsuccessful query result with error condition
24 MaterializedQueryResult(string error);
25
26 //! Fetches a DataChunk from the query result. Returns an empty chunk if the result is empty, or nullptr on failure.
27 //! This will consume the result (i.e. the chunks are taken directly from the ChunkCollection).
28 unique_ptr<DataChunk> Fetch() override;
29 //! Converts the QueryResult to a string
30 string ToString() override;
31
32 //! Gets the (index) value of the (column index) column
33 Value GetValue(idx_t column, idx_t index);
34
35 template <class T> T GetValue(idx_t column, idx_t index) {
36 auto value = GetValue(column, index);
37 return (T)value.GetValue<int64_t>();
38 }
39
40 ChunkCollection collection;
41};
42
43} // namespace duckdb
44