From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001 From: John Turner Date: Sun, 14 Sep 2025 00:16:10 -0400 Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35 git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c --- include/boost/sqlite/row.hpp | 167 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 include/boost/sqlite/row.hpp (limited to 'include/boost/sqlite/row.hpp') diff --git a/include/boost/sqlite/row.hpp b/include/boost/sqlite/row.hpp new file mode 100644 index 0000000..6893f96 --- /dev/null +++ b/include/boost/sqlite/row.hpp @@ -0,0 +1,167 @@ +// Copyright (c) 2022 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#ifndef BOOST_SQLITE_ROW_HPP +#define BOOST_SQLITE_ROW_HPP + +#include + +BOOST_SQLITE_BEGIN_NAMESPACE + +/** @brief Representation of a row in a database. + @ingroup reference + + Is a random-access range. + + All values that are obtained by view are valid until the next row is read. + + */ +struct row +{ + /// The size of the row + std::size_t size() const + { + return sqlite3_column_count(stm_); + } + /// Returns the field at `idx`, @throws std::out_of_range + BOOST_SQLITE_DECL + field at(std::size_t idx) const; + /// Returns the field at `idx`. + field operator[](std::size_t idx) const + { + field f; + f.stm_ = stm_; + f.col_ = static_cast(idx); + return f; + } + /// Random access iterator used to iterate over the columns. + struct const_iterator + { + using difference_type = int; + using reference = field&; + using iterator_category = std::random_access_iterator_tag; + + const_iterator & operator++() + { + f_.col_++; + return *this; + } + + const_iterator operator++(int) + { + auto last = *this; + ++(*this); + return last; + } + + const_iterator & operator--() + { + f_.col_--; + return *this; + } + + const_iterator operator--(int) + { + auto last = *this; + --(*this); + return last; + } + + field operator[](int i) const + { + auto f = f_; + f.col_ += i; + return f; + } + + const_iterator operator+(int i) const + { + auto r = *this; + r.f_.col_ += i; + return r; + } + + const_iterator operator-(int i) const + { + auto r = *this; + r.f_.col_ -= i; + return r; + } + + const_iterator & operator+=(int i) + { + f_.col_ += i; + return *this; + } + + const_iterator & operator-=(int i) + { + f_.col_ -= i; + return *this; + } + + const field & operator*() const + { + return f_; + } + + const field * operator->() const + { + return &f_; + } + + bool operator==(const const_iterator& other) const + { + return f_.col_ == other.f_.col_ + && f_.stm_ == other.f_.stm_; + } + + bool operator!=(const const_iterator& other) const + { + return f_.col_ != other.f_.col_ + || f_.stm_ != other.f_.stm_; + } + + bool operator<(const const_iterator& other) const + { + return f_.col_ < other.f_.col_ + && f_.stm_ < other.f_.stm_; + } + + bool operator>(const const_iterator& other) const + { + return f_.col_ > other.f_.col_ + && f_.stm_ > other.f_.stm_; + } + + const_iterator() = default; + private: + friend struct row; + field f_; + }; + /// Returns the begin of the column-range. + const_iterator begin() const + { + const_iterator ci; + ci.f_.col_ = 0; + ci.f_.stm_ = stm_; + return ci; + } + /// Returns the end of the column-range. + const_iterator end() const + { + const_iterator ci; + ci.f_.col_ = sqlite3_column_count(stm_); + ci.f_.stm_ = stm_; + return ci; + } + private: + friend struct resultset; + sqlite3_stmt * stm_; + +}; + +BOOST_SQLITE_END_NAMESPACE + +#endif //BOOST_SQLITE_ROW_HPP -- cgit v1.2.3