userver: /data/code/userver/odbc/include/userver/storages/odbc/cursor.hpp Source File
Loading...
Searching...
No Matches
cursor.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/odbc/cursor.hpp
4/// @brief @copybrief storages::odbc::Cursor
5
6#include <cstddef>
7#include <memory>
8
9#include <userver/storages/odbc/result_set.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace storages::odbc {
14
15namespace detail {
16class CursorImpl;
17class ClusterImpl;
18} // namespace detail
19
20/// @brief A move-only incremental ODBC result cursor.
21///
22/// Each Fetch materializes at most the requested number of rows into an owning
23/// ResultSet. The cursor pins its connection until EOF, destruction, or an
24/// error. This bounds memory materialized by userver, but an ODBC driver may
25/// still buffer rows internally and server-side streaming is not guaranteed.
26/// Fetch calls on a cursor must be sequential.
27class Cursor final {
28public:
29 Cursor(const Cursor&) = delete;
30 Cursor& operator=(const Cursor&) = delete;
31
32 Cursor(Cursor&&) noexcept;
33 Cursor& operator=(Cursor&&) noexcept;
34 ~Cursor() noexcept;
35
36 /// @brief Fetch up to @p rows and return an owning result chunk.
37 /// @throws LogicError if rows is zero or the cursor is already terminal.
38 ResultSet Fetch(std::size_t rows);
39
40 /// @brief Whether EOF, an error, invalidation, or a moved-from state has
41 /// made this cursor terminal.
42 bool Done() const noexcept;
43
44 /// @brief Number of rows returned by successful Fetch calls.
45 std::size_t FetchedSoFar() const noexcept;
46
47 explicit operator bool() const noexcept { return !Done(); }
48
49private:
50 friend class detail::ClusterImpl;
51 friend class Transaction;
52
53 explicit Cursor(std::shared_ptr<detail::CursorImpl> impl);
54
55 std::shared_ptr<detail::CursorImpl> impl_;
56};
57
58} // namespace storages::odbc
59
60USERVER_NAMESPACE_END