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
00056 class PQXX_LIBEXPORT Cursor
00057 {
00058 public:
00059
00060 typedef Result::size_type size_type;
00061
00062 enum pos { pos_unknown = -1, pos_start = 0 };
00063
00065 struct unknown_position : PGSTD::runtime_error
00066 {
00067 unknown_position(const PGSTD::string &cursorname) :
00068 PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00069 "is unknown")
00070 {
00071 }
00072 };
00073
00075
00083 Cursor(TransactionItf &T,
00084 const char Query[],
00085 const PGSTD::string &BaseName="cur",
00086 size_type Count=NEXT());
00087
00089 size_type SetCount(size_type);
00090
00092
00101 Result Fetch(size_type Count);
00102
00104
00112 size_type Move(size_type Count);
00113
00114 void MoveTo(size_type);
00115
00117
00121 static size_type ALL() throw ()
00122 { return PGSTD::numeric_limits<Result::size_type>::max(); }
00123
00125 static size_type NEXT() throw () { return 1; }
00126
00128 static size_type PRIOR() throw () { return -1; }
00129
00132
00136 static size_type BACKWARD_ALL() throw ()
00137 { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00138
00140
00147 Cursor &operator>>(Result &);
00148
00150 operator bool() const throw () { return !m_Done; }
00152
00153
00155 Cursor &operator+=(size_type N) { Move(N); return *this;}
00157
00158
00160
00171 size_type size() const throw () { return m_Size; }
00172
00174
00181 size_type Pos() const throw (unknown_position)
00182 { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00183
00184
00185 private:
00186 static PGSTD::string OffsetString(size_type);
00187 PGSTD::string MakeFetchCmd(size_type) const;
00188 size_type NormalizedMove(size_type Intended, size_type Actual);
00189
00190 TransactionItf &m_Trans;
00191 PGSTD::string m_Name;
00192 size_type m_Count;
00193 bool m_Done;
00194 size_type m_Pos;
00195 size_type m_Size;
00196
00197
00198 Cursor(const Cursor &);
00199 Cursor &operator=(const Cursor &);
00200 };
00201
00202 }
00203
00204 #endif
00205