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/compiler-public.hxx"
00022 #include "pqxx/compiler-internal-pre.hxx"
00023
00024 #include "pqxx/result"
00025 #include "pqxx/transaction_base"
00026 #include "pqxx/util"
00027
00028
00029
00030
00031 namespace pqxx
00032 {
00033 class result;
00034
00035
00036
00037 #ifdef __MWERKS__
00038 #pragma defer_defarg_parsing on
00039 #endif
00040
00041
00043
00073 class PQXX_LIBEXPORT Cursor
00074 {
00075 enum { dist_next=1 };
00076
00077 public:
00078 typedef result::size_type size_type;
00079 typedef result::difference_type difference_type;
00080
00081 enum pos { pos_unknown = -1, pos_start = 0 };
00082
00084 struct PQXX_LIBEXPORT unknown_position : PGSTD::runtime_error
00085 {
00086 unknown_position(const PGSTD::string &cursorname) :
00087 PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00088 "is unknown")
00089 {
00090 }
00091 };
00092
00094
00102 template<typename TRANSACTION>
00103 Cursor(TRANSACTION &T,
00104 const char Query[],
00105 const PGSTD::string &BaseName="cur",
00106 difference_type Count=dist_next) :
00107 m_Trans(T),
00108 m_Name(T.conn().adorn_name(BaseName)),
00109 m_Count(Count),
00110 m_Done(false),
00111 m_Pos(pos_start),
00112 m_Size(pos_unknown)
00113 {
00114
00115 error_permitted_isolation_level(PQXX_TYPENAME TRANSACTION::isolation_tag());
00116 init(Query);
00117 }
00118
00120
00150 template<typename TRANSACTION>
00151 Cursor(TRANSACTION &T,
00152 const result::field &Name,
00153 difference_type Count=dist_next) :
00154 m_Trans(T),
00155 m_Name(Name.c_str()),
00156 m_Count(Count),
00157 m_Done(false),
00158 m_Pos(size_type(pos_unknown)),
00159 m_Size(size_type(pos_unknown))
00160 {
00161
00162 error_permitted_isolation_level(PQXX_TYPENAME TRANSACTION::isolation_tag());
00163 }
00164
00166 difference_type SetCount(difference_type);
00167
00169
00178 result Fetch(difference_type Count);
00179
00181
00189 difference_type Move(difference_type Count);
00190
00191 void MoveTo(size_type);
00192
00194
00198 static difference_type ALL() throw ();
00199
00201 static difference_type NEXT() throw () { return dist_next; }
00202
00204 static difference_type PRIOR() throw () { return -1; }
00205
00208
00212 static difference_type BACKWARD_ALL() throw ();
00213
00215
00222 Cursor &operator>>(result &);
00223
00225 operator bool() const throw () { return !m_Done; }
00227 bool operator!() const throw () { return m_Done; }
00228
00230 Cursor &operator+=(difference_type N) { Move(N); return *this;}
00232 Cursor &operator-=(difference_type N) { Move(-N); return *this;}
00233
00235
00246 size_type size() const throw () { return m_Size; }
00247
00249
00256 size_type Pos() const throw (unknown_position)
00257 {
00258 if (m_Pos==size_type(pos_unknown)) throw unknown_position(m_Name);
00259 return m_Pos;
00260 }
00261
00262
00263 private:
00264 static PGSTD::string OffsetString(difference_type);
00265 void init(const char Query[]);
00266 PGSTD::string MakeFetchCmd(difference_type) const;
00267 difference_type NormalizedMove(difference_type Intended,
00268 difference_type Actual);
00269
00271
00275 static void
00276 error_permitted_isolation_level(isolation_traits<serializable>) throw () {}
00277
00278 transaction_base &m_Trans;
00279 PGSTD::string m_Name;
00280 difference_type m_Count;
00281 bool m_Done;
00282 size_type m_Pos;
00283 difference_type m_Size;
00284
00285
00286 Cursor(const Cursor &);
00287 Cursor &operator=(const Cursor &);
00288 };
00289
00290
00291 }
00292
00293 #include "pqxx/compiler-internal-post.hxx"
00294
00295 #endif
00296