summaryrefslogtreecommitdiff
path: root/subprojects/boost-sqlite/include/boost/sqlite/row.hpp
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
commit13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch)
tree1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/include/boost/sqlite/row.hpp
parentaa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff)
parentefcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff)
downloadsqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/include/boost/sqlite/row.hpp')
-rw-r--r--subprojects/boost-sqlite/include/boost/sqlite/row.hpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/include/boost/sqlite/row.hpp b/subprojects/boost-sqlite/include/boost/sqlite/row.hpp
new file mode 100644
index 0000000..6893f96
--- /dev/null
+++ b/subprojects/boost-sqlite/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/field.hpp>
+
+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<int>(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