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
00058 class PQXX_LIBEXPORT Cursor
00059 {
00060 public:
00061
00062 typedef Result::size_type size_type;
00063
00064 enum pos { pos_unknown = -1, pos_start = 0 };
00065
00067 struct unknown_position : PGSTD::runtime_error
00068 {
00069 unknown_position(const PGSTD::string &cursorname) :
00070 PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00071 "is unknown")
00072 {
00073 }
00074 };
00075
00077
00085 Cursor(TransactionItf &T,
00086 const char Query[],
00087 const PGSTD::string &BaseName="cur",
00088 size_type Count=NEXT());
00089
00091
00121 Cursor(TransactionItf &T,
00122 const Result::Field &Name,
00123 size_type Count=NEXT());
00124
00126 size_type SetCount(size_type);
00127
00129
00138 Result Fetch(size_type Count);
00139
00141
00149 size_type Move(size_type Count);
00150
00151 void MoveTo(size_type);
00152
00154
00158 static size_type ALL() throw ()
00159 { return PGSTD::numeric_limits<Result::size_type>::max(); }
00160
00162 static size_type NEXT() throw () { return 1; }
00163
00165 static size_type PRIOR() throw () { return -1; }
00166
00169
00173 static size_type BACKWARD_ALL() throw ()
00174 { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00175
00177
00184 Cursor &operator>>(Result &);
00185
00187 operator bool() const throw () { return !m_Done; }
00189
00190
00192 Cursor &operator+=(size_type N) { Move(N); return *this;}
00194
00195
00197
00208 size_type size() const throw () { return m_Size; }
00209
00211
00218 size_type Pos() const throw (unknown_position)
00219 { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00220
00221
00222 private:
00223 static PGSTD::string OffsetString(size_type);
00224 PGSTD::string MakeFetchCmd(size_type) const;
00225 size_type NormalizedMove(size_type Intended, size_type Actual);
00226
00227 TransactionItf &m_Trans;
00228 PGSTD::string m_Name;
00229 size_type m_Count;
00230 bool m_Done;
00231 size_type m_Pos;
00232 size_type m_Size;
00233
00234
00235 Cursor(const Cursor &);
00236 Cursor &operator=(const Cursor &);
00237 };
00238
00239 }
00240
00241 #endif
00242