Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cursor.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/cursor.h
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::Cursor class.
00008  *   pqxx::Cursor represents a database cursor.
00009  *
00010  * Copyright (c) 2001-2004, Jeroen T. Vermeulen <jtv@xs4all.nl>
00011  *
00012  * See COPYING for copyright license.  If you did not receive a file called
00013  * COPYING with this source code, please notify the distributor of this mistake,
00014  * or contact the author.
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 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00026  */
00027 
00028 namespace pqxx
00029 {
00030 class result;
00031 
00032 
00033 // Work around bug in CodeWarrior 8.3
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) :                           //[t3]
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     // Trigger build error if T has insufficient isolation level
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) :                           //[t45]
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     // Trigger build error if T has insufficient isolation level
00159     error_permitted_isolation_level(PQXX_TYPENAME TRANSACTION::isolation_tag());
00160   }
00161 
00163   difference_type SetCount(difference_type);                            //[t19]
00164 
00166 
00175   result Fetch(difference_type Count);                                  //[t19]
00176 
00178 
00186   difference_type Move(difference_type Count);                          //[t42]
00187 
00188   void MoveTo(size_type);                                               //[t44]
00189 
00191 
00195   static difference_type ALL() throw ();                                //[t3]
00196 
00198   static difference_type NEXT() throw () { return dist_next; }          //[t19]
00199 
00201   static difference_type PRIOR() throw () { return -1; }                //[t19]
00202 
00205 
00209   static difference_type BACKWARD_ALL() throw ();                       //[t19]
00210 
00212 
00219   Cursor &operator>>(result &);                                         //[t3]
00220 
00222   operator bool() const throw () { return !m_Done; }                    //[t3]
00224   bool operator!() const throw () { return m_Done; }                    //[t3]
00225 
00227   Cursor &operator+=(difference_type N) { Move(N); return *this;}       //[t19]
00229   Cursor &operator-=(difference_type N) { Move(-N); return *this;}      //[t19]
00230 
00232 
00243   size_type size() const throw () { return m_Size; }                    //[t44]
00244 
00246 
00253   size_type Pos() const throw (unknown_position)                        //[t43]
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   // Incorrect, but needed to compile with Sun CC
00278   template<> static void 
00279     error_permitted_level(isolation_traits<serializable>) throw() {}
00280 #endif  // __SUNPRO_CC
00281 #else
00282   // Incorrect, but needed to compile with Visual C++ 7
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   // Not allowed:
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 } // namespace pqxx
00304 
00305 #endif
00306 

Generated on Mon Nov 15 11:27:59 2004 for libpqxx by  doxygen 1.3.9.1