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>(); }
 
   88   template <
typename ReturnType>
 
   89   ReturnType 
get() 
const;
 
   95   bool isNull() const noexcept { 
return !value_.value; }
 
  101   friend bool operator==(
const Value& lhs, 
const Value& rhs) 
noexcept { 
return lhs.value_.value == rhs.value_.value; }
 
  108   template <
typename ReturnType>
 
  109   friend struct internal::ValueAccess;
 
  119   hyper_value_t value_{
nullptr, 0};
 
  121   SqlType type_{TypeTag::Unsupported, 0};
 
  123   string_view columnName_ = 
"";
 
  164   bool isOpen() const noexcept { 
return (chunk_ != 
nullptr); }
 
  167   operator bool() const noexcept { 
return isOpen(); }
 
  181   Chunk(hyper_rowset_chunk_t* chunk, 
const Result& result) 
noexcept;
 
  184   hyper_rowset_chunk_t* chunk_ = 
nullptr;
 
  186   mutable const uint8_t* 
const* values_ = 
nullptr;
 
  188   mutable const size_t* valuesSizes_ = 
nullptr;
 
  190   size_t chunkSize_ = 0;
 
  192   const Result* result_ = 
nullptr;
 
  194   size_t rowCount_ = 0;
 
  197   const uint8_t* 
const* getValues() const noexcept;
 
  199   const 
size_t* getValuesSizes() const noexcept;
 
  222   template <
typename ReturnType = Value>
 
  223   ReturnType 
get(hyper_field_index_t columnIndex) 
const;
 
  238   Row(const 
Chunk& chunk, hyper_row_index_t chunkRowIndex) noexcept;
 
  241   Row(const 
Row&) = default;
 
  243   Row& operator=(const 
Row&) = default;
 
  244   Row& operator=(
Row&&) = default;
 
  247   std::reference_wrapper<const 
Chunk> chunk_;
 
  249   hyper_row_index_t chunkRowIndex_;
 
  270   using iterator_category = std::input_iterator_tag;
 
  272   using difference_type = std::ptrdiff_t;
 
  278      : chunk_(chunk), rowIndex_(0), currentRow_(chunk, 0) {
 
  283      : chunk_(chunk), rowIndex_(
static_cast<hyper_row_index_t
>(chunk.getRowCount())), currentRow_(chunk, 0) {
 
  290   pointer operator->() const noexcept { 
return &**
this; }
 
  299   friend 
bool operator==(const 
ChunkIterator& lhs, const 
ChunkIterator& rhs) noexcept { 
return (lhs.chunk_.get() == rhs.chunk_.get()) && (lhs.rowIndex_ == rhs.rowIndex_); }
 
  305   std::reference_wrapper<const Chunk> chunk_;
 
  306   hyper_row_index_t rowIndex_;
 
  307   mutable Row currentRow_;
 
  314   return {chunk, iteratorBeginTag};
 
  319   return {chunk, iteratorEndTag};
 
  379   void close() noexcept;
 
  395   void fetchNextChunk();
 
  398   Chunk& getCurrentChunk();
 
  407   hyper_rowset_t* rowset_ = 
nullptr;
 
  425   friend 
Result internal::executePreparedQuery(
Connection& connection, const std::
string& statement_name, hyper_rowset_result_format_t result_format);
 
  426   friend 
Result internal::executeQueryParams(
Connection& connection, const std::
string& query, hyper_rowset_result_format_t result_format);
 
  429   friend inline 
bool internal::hasCopyData(
Result&);
 
  430   friend inline internal::CopyData internal::getCopyData(
Result& result);
 
  431   friend inline hyper_rowset_type_t internal::getResultType(
Result& result);
 
  447   using iterator_category = std::input_iterator_tag;
 
  449   using difference_type = std::ptrdiff_t;
 
  455      : row_(row), columnIndex_(0) {
 
  460      : row_(row), columnIndex_(
static_cast<hyper_field_index_t
>(row.getSchema().getColumnCount())) {
 
  467   pointer operator->() const noexcept { 
return &**
this; }
 
  482   std::reference_wrapper<const Row> row_;
 
  483   hyper_field_index_t columnIndex_;
 
  484   mutable Value currentValue_;
 
  489   return {row, iteratorBeginTag};
 
  494   return {row, iteratorEndTag};
 
  500   using iterator_category = std::input_iterator_tag;
 
  502   using difference_type = std::ptrdiff_t;
 
  510      : result_(result), isEndIterator_(
true) {
 
  530   std::reference_wrapper<Result> result_;
 
  537   return {chunks.
result, iteratorBeginTag};
 
  542   return {chunks.result, iteratorEndTag};
 
  553   using iterator_category = std::input_iterator_tag;
 
  555   using difference_type = std::ptrdiff_t;
 
  563      : result_(result), isEndIterator_(
true) {
 
  583   std::reference_wrapper<Result> result_;
 
  590   return {result, iteratorBeginTag};
 
  595   return {result, iteratorEndTag};
 
  599#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.