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
00076
00078
00079 * @param T is the transaction that this cursor lives in.
00080 * @param Query defines a data set that the cursor should traverse.
00081 * @param BaseName optional name for the cursor, must begin with a letter
00082 * and contain letters and digits only.
00083 * @param Count the stride of the cursor, ie. the number of rows fetched at a
00084 * time. This defaults to 1.
00085 */
00086 Cursor(TransactionItf &T,
00087 const char Query[],
00088 const PGSTD::string &BaseName="cur",
00089 size_type Count=NEXT());
00090
00092
00122 Cursor(TransactionItf &T,
00123 const Result::Field &Name,
00124 size_type Count=NEXT());
00125
00127 size_type SetCount(size_type);
00128
00130
00139 Result Fetch(size_type Count);
00140
00142
00150 size_type Move(size_type Count);
00151
00152 void MoveTo(size_type);
00153
00155
00159 static size_type ALL() throw ()
00160 { return PGSTD::numeric_limits<Result::size_type>::max(); }
00161
00163 static size_type NEXT() throw () { return 1; }
00164
00166 static size_type PRIOR() throw () { return -1; }
00167
00170
00174 static size_type BACKWARD_ALL() throw ()
00175 { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00176
00178
00185 Cursor &operator>>(Result &);
00186
00188 operator bool() const throw () { return !m_Done; }
00190
00191
00193 Cursor &operator+=(size_type N) { Move(N); return *this;}
00195
00196
00198
00209 size_type size() const throw () { return m_Size; }
00210
00212
00219 size_type Pos() const throw (unknown_position)
00220 { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00221
00222
00223 private:
00224 static PGSTD::string OffsetString(size_type);
00225 PGSTD::string MakeFetchCmd(size_type) const;
00226 size_type NormalizedMove(size_type Intended, size_type Actual);
00227
00228 TransactionItf &m_Trans;
00229 PGSTD::string m_Name;
00230 size_type m_Count;
00231 bool m_Done;
00232 size_type m_Pos;
00233 size_type m_Size;
00234
00235
00236 Cursor(const Cursor &);
00237 Cursor &operator=(const Cursor &);
00238 };
00239
00240 }
00241
00242 #endif
00243