00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef PQXX_OLD_CURSOR_H
00019 #define PQXX_OLD_CURSOR_H
00020
00021 #include "pqxx/result.h"
00022 #include "pqxx/transaction_base.h"
00023 #include "pqxx/util.h"
00024
00025
00026
00027
00028 namespace pqxx
00029 {
00030 class result;
00031
00032
00033
00034 #ifdef __MWERKS__
00035 #pragma defer_defarg_parsing on
00036 #endif
00037
00038
00040
00070 class PQXX_LIBEXPORT Cursor
00071 {
00072 enum { dist_next=1 };
00073
00074 public:
00075 typedef result::size_type size_type;
00076 typedef result::difference_type difference_type;
00077
00078 enum pos { pos_unknown = -1, pos_start = 0 };
00079
00081 struct PQXX_LIBEXPORT unknown_position : PGSTD::runtime_error
00082 {
00083 unknown_position(const PGSTD::string &cursorname) :
00084 PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00085 "is unknown")
00086 {
00087 }
00088 };
00089
00091
00099 template<typename TRANSACTION>
00100 Cursor(TRANSACTION &T,
00101 const char Query[],
00102 const PGSTD::string &BaseName="cur",
00103 difference_type Count=dist_next) :
00104 m_Trans(T),
00105 m_Name(),
00106 m_Count(Count),
00107 m_Done(false),
00108 m_Pos(pos_start),
00109 m_Size(pos_unknown)
00110 {
00111
00112 error_permitted_isolation_level(PQXX_TYPENAME TRANSACTION::isolation_tag());
00113 init(BaseName, Query);
00114 }
00115
00117
00147 template<typename TRANSACTION>
00148 Cursor(TRANSACTION &T,
00149 const result::field &Name,
00150 difference_type Count=dist_next) :
00151 m_Trans(T),
00152 m_Name(Name.c_str()),
00153 m_Count(Count),
00154 m_Done(false),
00155 m_Pos(size_type(pos_unknown)),
00156 m_Size(size_type(pos_unknown))
00157 {
00158
00159 error_permitted_isolation_level(PQXX_TYPENAME TRANSACTION::isolation_tag());
00160 }
00161
00163 difference_type SetCount(difference_type);
00164
00166
00175 result Fetch(difference_type Count);
00176
00178
00186 difference_type Move(difference_type Count);
00187
00188 void MoveTo(size_type);
00189
00191
00195 static difference_type ALL() throw ();
00196
00198 static difference_type NEXT() throw () { return dist_next; }
00199
00201 static difference_type PRIOR() throw () { return -1; }
00202
00205
00209 static difference_type BACKWARD_ALL() throw ();
00210
00212
00219 Cursor &operator>>(result &);
00220
00222 operator bool() const throw () { return !m_Done; }
00224 bool operator!() const throw () { return m_Done; }
00225
00227 Cursor &operator+=(difference_type N) { Move(N); return *this;}
00229 Cursor &operator-=(difference_type N) { Move(-N); return *this;}
00230
00232
00243 size_type size() const throw () { return m_Size; }
00244
00246
00253 size_type Pos() const throw (unknown_position)
00254 {
00255 if (m_Pos==size_type(pos_unknown)) throw unknown_position(m_Name);
00256 return m_Pos;
00257 }
00258
00259
00260 private:
00261 static PGSTD::string OffsetString(difference_type);
00262 void init(const PGSTD::string &BaseName, const char Query[]);
00263 PGSTD::string MakeFetchCmd(difference_type) const;
00264 difference_type NormalizedMove(difference_type Intended,
00265 difference_type Actual);
00266
00267 #ifndef PQXX_WORKAROUND_VC7
00268
00269
00273 template<typename ISOLATIONTAG>
00274 static inline void error_permitted_isolation_level(ISOLATIONTAG) throw();
00275
00276 #if defined(__SUNPRO_CC)
00277
00278 template<> static void
00279 error_permitted_level(isolation_traits<serializable>) throw() {}
00280 #endif // __SUNPRO_CC
00281 #else
00282
00283 template<> static inline void
00284 error_permitted_isolation_level(isolation_traits<serializable>) throw ();
00285 #endif
00286
00287 transaction_base &m_Trans;
00288 PGSTD::string m_Name;
00289 difference_type m_Count;
00290 bool m_Done;
00291 size_type m_Pos;
00292 difference_type m_Size;
00293
00294
00295 Cursor(const Cursor &);
00296 Cursor &operator=(const Cursor &);
00297 };
00298
00299 template<> inline void
00300 Cursor::error_permitted_isolation_level(isolation_traits<serializable>) throw ()
00301 {}
00302
00303 }
00304
00305 #endif
00306