5#ifndef TABLEAU_HYPER_RESULT_HPP
6#define TABLEAU_HYPER_RESULT_HPP
11#include <hyperapi/hyperapi.h>
25class ChunkedResultIterator;
28inline bool hasCopyData(Result& result);
30inline CopyData getCopyData(Result& result);
31inline hyper_rowset_type_t getResultType(Result& result);
41 : value_(value), type_(type), columnName_(columnName) {
51 template <
typename ReturnType>
52 operator ReturnType()
const {
return get<ReturnType>(); }
81 template <
typename ReturnType>
82 ReturnType
get()
const;
88 bool isNull() const noexcept {
return !value_.value; }
94 friend bool operator==(
const Value& lhs,
const Value& rhs)
noexcept {
return lhs.value_.value == rhs.value_.value; }
101 template <
typename ReturnType>
102 friend struct internal::ValueAccess;
112 hyper_value_t value_{
nullptr, 0};
114 SqlType type_{TypeTag::Unsupported, 0};
116 string_view columnName_ =
"";
157 bool isOpen() const noexcept {
return (chunk_ !=
nullptr); }
160 operator bool() const noexcept {
return isOpen(); }
174 Chunk(hyper_rowset_chunk_t* chunk,
const Result& result)
noexcept;
177 hyper_rowset_chunk_t* chunk_ =
nullptr;
179 mutable const uint8_t*
const* values_ =
nullptr;
181 mutable const size_t* valuesSizes_ =
nullptr;
183 size_t chunkSize_ = 0;
185 const Result* result_ =
nullptr;
187 size_t rowCount_ = 0;
190 const uint8_t*
const* getValues() const noexcept;
192 const
size_t* getValuesSizes() const noexcept;
215 template <
typename ReturnType = Value>
216 ReturnType
get(hyper_field_index_t columnIndex)
const;
231 Row(const
Chunk& chunk, hyper_row_index_t chunkRowIndex) noexcept;
234 Row(const
Row&) = default;
236 Row& operator=(const
Row&) = default;
237 Row& operator=(
Row&&) = default;
240 std::reference_wrapper<const
Chunk> chunk_;
242 hyper_row_index_t chunkRowIndex_;
263 using iterator_category = std::input_iterator_tag;
265 using difference_type = std::ptrdiff_t;
271 : chunk_(chunk), rowIndex_(0), currentRow_(chunk, 0) {
276 : chunk_(chunk), rowIndex_(
static_cast<hyper_row_index_t
>(chunk.getRowCount())), currentRow_(chunk, 0) {
283 pointer operator->() const noexcept {
return &**
this; }
292 friend
bool operator==(const
ChunkIterator& lhs, const
ChunkIterator& rhs) noexcept {
return (lhs.chunk_.get() == rhs.chunk_.get()) && (lhs.rowIndex_ == rhs.rowIndex_); }
298 std::reference_wrapper<const Chunk> chunk_;
299 hyper_row_index_t rowIndex_;
300 mutable Row currentRow_;
307 return {chunk, iteratorBeginTag};
312 return {chunk, iteratorEndTag};
372 void close() noexcept;
388 void fetchNextChunk();
391 Chunk& getCurrentChunk();
400 hyper_rowset_t* rowset_ =
nullptr;
418 friend
Result internal::executePreparedQuery(
Connection& connection, const std::
string& statement_name, hyper_rowset_result_format_t result_format);
419 friend
Result internal::executeQueryParams(
Connection& connection, const std::
string& query, hyper_rowset_result_format_t result_format);
422 friend inline
bool internal::hasCopyData(
Result&);
423 friend inline internal::CopyData internal::getCopyData(
Result& result);
424 friend inline hyper_rowset_type_t internal::getResultType(
Result& result);
440 using iterator_category = std::input_iterator_tag;
442 using difference_type = std::ptrdiff_t;
448 : row_(row), columnIndex_(0) {
453 : row_(row), columnIndex_(
static_cast<hyper_field_index_t
>(row.getSchema().getColumnCount())) {
460 pointer operator->() const noexcept {
return &**
this; }
475 std::reference_wrapper<const Row> row_;
476 hyper_field_index_t columnIndex_;
477 mutable Value currentValue_;
482 return {row, iteratorBeginTag};
487 return {row, iteratorEndTag};
493 using iterator_category = std::input_iterator_tag;
495 using difference_type = std::ptrdiff_t;
503 : result_(result), isEndIterator_(
true) {
523 std::reference_wrapper<Result> result_;
530 return {chunks.
result, iteratorBeginTag};
535 return {chunks.result, iteratorEndTag};
546 using iterator_category = std::input_iterator_tag;
548 using difference_type = std::ptrdiff_t;
556 : result_(result), isEndIterator_(
true) {
576 std::reference_wrapper<Result> result_;
583 return {result, iteratorBeginTag};
588 return {result, iteratorEndTag};
592#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.