5#ifndef TABLEAU_HYPER_RESULT_HPP
6#define TABLEAU_HYPER_RESULT_HPP
18#include <hyperapi/hyperapi.h>
32class ChunkedResultIterator;
35inline bool hasCopyData(Result& result);
37inline CopyData getCopyData(Result& result);
38inline hyper_rowset_type_t getResultType(Result& result);
48 : value(value), type(type), columnName(columnName) {
58 template <
typename ReturnType>
59 operator ReturnType()
const {
return get<ReturnType>(); }
87 template <
typename ReturnType>
88 ReturnType
get()
const;
94 bool isNull() const noexcept {
return !value.value; }
100 friend bool operator==(
const Value& lhs,
const Value& rhs)
noexcept {
return lhs.value.value == rhs.value.value; }
107 template <
typename ReturnType>
108 friend struct internal::ValueAccess;
118 hyper_value_t value{
nullptr, 0};
120 SqlType type{TypeTag::Unsupported, 0};
122 string_view columnName =
"";
163 bool isOpen() const noexcept {
return (chunk !=
nullptr); }
166 operator bool() const noexcept {
return isOpen(); }
180 Chunk(hyper_rowset_chunk_t* chunk,
const Result& result)
noexcept;
183 hyper_rowset_chunk_t* chunk =
nullptr;
185 mutable const uint8_t*
const* values =
nullptr;
187 mutable const size_t* valuesSizes =
nullptr;
189 size_t chunkSize = 0;
191 const Result* result =
nullptr;
196 const uint8_t*
const* getValues() const noexcept;
198 const
size_t* getValuesSizes() const noexcept;
221 template <
typename ReturnType = Value>
222 ReturnType
get(hyper_field_index_t columnIndex)
const;
237 Row(const
Chunk& chunk, hyper_row_index_t chunkRowIndex) noexcept;
240 Row(const
Row&) = default;
242 Row& operator=(const
Row&) = default;
243 Row& operator=(
Row&&) = default;
246 std::reference_wrapper<const
Chunk> chunk;
248 hyper_row_index_t chunkRowIndex;
269 using iterator_category = std::input_iterator_tag;
271 using difference_type = std::ptrdiff_t;
277 : chunk(chunk), rowIndex(0), currentRow(chunk, 0) {
282 : chunk(chunk), rowIndex(
static_cast<hyper_row_index_t
>(chunk.getRowCount())), currentRow(chunk, 0) {
289 pointer operator->() const noexcept {
return &**
this; }
298 friend
bool operator==(const
ChunkIterator& lhs, const
ChunkIterator& rhs) noexcept {
return (lhs.chunk.get() == rhs.chunk.get()) && (lhs.rowIndex == rhs.rowIndex); }
304 std::reference_wrapper<const Chunk> chunk;
305 hyper_row_index_t rowIndex;
306 mutable Row currentRow;
313 return {chunk, iteratorBeginTag};
318 return {chunk, iteratorEndTag};
378 void close() noexcept;
394 void fetchNextChunk();
397 Chunk& getCurrentChunk();
406 hyper_rowset_t* rowset =
nullptr;
424 friend
Result internal::executePreparedQuery(
Connection& connection, const std::
string& statement_name, hyper_rowset_result_format_t result_format);
425 friend
Result internal::executeQueryParams(
Connection& connection, const std::
string& query, hyper_rowset_result_format_t result_format);
428 friend inline
bool internal::hasCopyData(
Result&);
429 friend inline internal::CopyData internal::getCopyData(
Result& result);
430 friend inline hyper_rowset_type_t internal::getResultType(
Result& result);
446 using iterator_category = std::input_iterator_tag;
448 using difference_type = std::ptrdiff_t;
454 : row(row), columnIndex(0) {
459 : row(row), columnIndex(
static_cast<hyper_field_index_t
>(row.getSchema().getColumnCount())) {
466 pointer operator->() const noexcept {
return &**
this; }
481 std::reference_wrapper<const Row> row;
482 hyper_field_index_t columnIndex;
483 mutable Value currentValue;
488 return {row, iteratorBeginTag};
493 return {row, iteratorEndTag};
499 using iterator_category = std::input_iterator_tag;
501 using difference_type = std::ptrdiff_t;
509 : result(result), isEndIterator(
true) {
529 std::reference_wrapper<Result> result;
536 return {chunks.
result, iteratorBeginTag};
541 return {chunks.result, iteratorEndTag};
552 using iterator_category = std::input_iterator_tag;
554 using difference_type = std::ptrdiff_t;
562 : result(result), isEndIterator(
true) {
582 std::reference_wrapper<Result> result;
589 return {result, iteratorBeginTag};
594 return {result, iteratorEndTag};
598#include <hyperapi/impl/Result.impl.hpp>
Iterates over a hyperapi::Chunk in rows (hyperapi::Row).
friend bool operator!=(const ChunkIterator &lhs, const ChunkIterator &rhs) noexcept
Comparison operator.
ChunkIterator & operator++() noexcept
Advances the iterator.
ChunkIterator(const Chunk &chunk, IteratorEndTag) noexcept
Constructs the end-iterator.
reference operator*() const noexcept
Returns a reference to the current value.
ChunkIterator(const Chunk &chunk, IteratorBeginTag) noexcept
Constructs the begin-iterator.
friend bool operator==(const Chunk &lhs, const Chunk &rhs) noexcept
Comparison operator.
bool isOpen() const noexcept
Returns whether the chunk is valid.
Row getRowAt(hyper_row_index_t chunkRowIndex) const noexcept
Retrieves the row at the given index inside the chunk (starting at 0).
size_t getRowCount() const noexcept
Chunk() noexcept=default
Constructor, constructs a closed chunk.
friend bool operator!=(const Chunk &lhs, const Chunk &rhs) noexcept
Comparison operator.
Iterates over a hyperapi::Result in hyperapi::Chunk.
reference operator*() noexcept
Returns a reference to the current value.
friend bool operator!=(const ChunkedResultIterator &lhs, const ChunkedResultIterator &rhs) noexcept
Comparison operator.
pointer operator->() noexcept
Returns a pointer to the current value.
friend bool operator==(const ChunkedResultIterator &lhs, const ChunkedResultIterator &rhs) noexcept
Comparison operator.
ChunkedResultIterator & operator++()
Advances the iterator.
ChunkedResultIterator(Result &result, IteratorEndTag) noexcept
Constructs the end-iterator.
ChunkedResultIterator(Result &result, IteratorBeginTag)
Constructs the begin-iterator.
Iterates over a hyperapi::Row in values (hyperapi::Value).
reference operator*() const noexcept
Returns a reference to the current value.
ColumnIterator & operator++()
Advances the iterator.
friend bool operator==(const ColumnIterator &lhs, const ColumnIterator &rhs) noexcept
Comparison operator.
ColumnIterator operator++(int)
Advances the iterator.
friend bool operator!=(const ColumnIterator &lhs, const ColumnIterator &rhs) noexcept
Comparison operator.
ColumnIterator(const Row &row, IteratorEndTag) noexcept
Constructs the end-iterator.
ColumnIterator(const Row &row, IteratorBeginTag) noexcept
Constructs the begin-iterator.
Defines a Hyper connection.
Iterates over a hyperapi::Result in rows (hyperapi::Row).
ResultIterator(Result &result, IteratorBeginTag)
Constructs the begin-iterator.
friend bool operator==(const ResultIterator &lhs, const ResultIterator &rhs) noexcept
Comparison operator.
friend bool operator!=(const ResultIterator &lhs, const ResultIterator &rhs) noexcept
Comparison operator.
ResultIterator(Result &result, IteratorEndTag) noexcept
Constructs the end-iterator.
reference operator*() const noexcept
Returns a reference to the current value.
pointer operator->() const noexcept
Returns a pointer to the current value.
ResultIterator & operator++()
Advances the iterator.
Base class for a result of a query.
Connection & getConnection()
Returns the connection of the SQL statement that yielded this result.
bool isOpen() const noexcept
Checks whether the result is open.
optional< size_t > getAffectedRowCount() const
Get the affected row count, if the statement had any.
Result()
Constructs an empty Result object.
ReturnType get(hyper_field_index_t columnIndex) const
Returns the value of field at position columnIndex.
const ResultSchema & getSchema() const noexcept
Returns the schema of the row.
Value(hyper_value_t value, SqlType type, string_view columnName) noexcept
Constructs a Value object.
Value() noexcept
Default constructs a Value object.
bool isNull() const noexcept
Returns whether the value is null.
SqlType getType() const noexcept
Get the type of the value.
ReturnType get() const
Get the value as one of the supported types.
friend std::ostream & operator<<(std::ostream &os, const Value &value)
Stream output operator.
friend bool operator==(const Value &lhs, const Value &rhs) noexcept
Comparison operator.
friend bool operator!=(const Value &lhs, const Value &rhs) noexcept
Comparison operator.
Surrogate for C++17 std::optional
Describes an object that can refer to a constant, contiguous sequence of char-like objects.
The primary namespace of the Hyper API for C++.
ChunkIterator begin(const Chunk &chunk)
Returns the begin-iterator for the rows of the given chunk.
ChunkIterator end(const Chunk &chunk) noexcept
Returns the end-iterator for the rows of the given chunk.
A tag for an iterator-begin constructor.
A tag for an iterator-end constructor.
A tag that makes a result iterable in chunks.
Result & result
the result
Chunks(Result &result)
Construct a Chunks object.