00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PQXX_CURSOR_H
00015 #define PQXX_CURSOR_H
00016
00017 #include "pqxx/result.h"
00018 #include "pqxx/util.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 namespace pqxx
00030 {
00031 class Result;
00032 class TransactionItf;
00033
00035
00055 class PQXX_LIBEXPORT Cursor
00056 {
00057 public:
00058
00059 typedef Result::size_type size_type;
00060
00061 enum pos { pos_unknown = -1, pos_start = 0 };
00062
00064 struct unknown_position : PGSTD::runtime_error
00065 {
00066 unknown_position(const PGSTD::string &cursorname) :
00067 PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00068 "is unknown")
00069 {
00070 }
00071 };
00072
00074
00082 Cursor(TransactionItf &T,
00083 const char Query[],
00084 const PGSTD::string &BaseName="cur",
00085 size_type Count=NEXT());
00086
00088 size_type SetCount(size_type);
00089
00091
00100 Result Fetch(size_type Count);
00101
00103
00111 size_type Move(size_type Count);
00112
00113 void MoveTo(size_type);
00114
00116
00120 static size_type ALL() throw ()
00121 { return PGSTD::numeric_limits<Result::size_type>::max(); }
00122
00124 static size_type NEXT() throw () { return 1; }
00125
00127 static size_type PRIOR() throw () { return -1; }
00128
00131
00135 static size_type BACKWARD_ALL() throw ()
00136 { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00137
00139
00146 Cursor &operator>>(Result &);
00147
00149 operator bool() const throw () { return !m_Done; }
00151
00152
00154 Cursor &operator+=(size_type N) { Move(N); return *this;}
00156
00157
00159
00170 size_type size() const throw () { return m_Size; }
00171
00173
00180 size_type Pos() const throw (unknown_position)
00181 { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00182
00183
00184 private:
00185 static PGSTD::string OffsetString(size_type);
00186 PGSTD::string MakeFetchCmd(size_type) const;
00187 size_type NormalizedMove(size_type Intended, size_type Actual);
00188
00189 TransactionItf &m_Trans;
00190 PGSTD::string m_Name;
00191 size_type m_Count;
00192 bool m_Done;
00193 size_type m_Pos;
00194 size_type m_Size;
00195
00196
00197 Cursor(const Cursor &);
00198 Cursor &operator=(const Cursor &);
00199 };
00200
00201 }
00202
00203 #endif
00204