Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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-2003, Jeroen T. Vermeulen <jtv@xs4all.nl>
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 /* (A quick note on binary cursors:
00021  * These will require a lot of work.  First off, conversion to C++ datatypes
00022  * becomes more complex.  Second, some tradeoffs will need to be made between
00023  * dynamic (flexible) type handling and static (fast) type handling.)
00024  */
00025 
00026 /* Methods tested in eg. self-test program test1 are marked with "//[t1]"
00027  */
00028 
00029 namespace pqxx
00030 {
00031 class Result;
00032 class TransactionItf;
00033 
00035 
00055 class PQXX_LIBEXPORT Cursor
00056 {
00057 public:
00058   // TODO: This apparently being migrated from int to long in Postgres.
00059   typedef Result::size_type size_type;
00060 
00061   enum pos { pos_unknown = -1, pos_start = 0 };
00062 
00064   struct unknown_position : PGSTD::runtime_error
00065   {
00066     unknown_position(const PGSTD::string &cursorname) :
00067       PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00068                            "is unknown") 
00069     {
00070     }
00071   };
00072 
00074 
00082   Cursor(TransactionItf &T,
00083          const char Query[], 
00084          const PGSTD::string &BaseName="cur",
00085          size_type Count=NEXT());                                       //[t3]
00086 
00088   size_type SetCount(size_type);                                        //[t19]
00089 
00091 
00100   Result Fetch(size_type Count);                                        //[t19]
00101 
00103 
00111   size_type Move(size_type Count);                                      //[]
00112 
00113   void MoveTo(size_type);
00114 
00116 
00120   static size_type ALL() throw ()                                       //[t3]
00121         { return PGSTD::numeric_limits<Result::size_type>::max(); }
00122 
00124   static size_type NEXT() throw () { return 1; }                        //[t19]
00125 
00127   static size_type PRIOR() throw () { return -1; }                      //[t19]
00128 
00131 
00135   static size_type BACKWARD_ALL() throw ()                              //[t19]
00136         { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00137 
00139 
00146   Cursor &operator>>(Result &);                                         //[t3]
00147 
00149   operator bool() const throw () { return !m_Done; }                    //[t3]
00151   bool operator!() const throw () { return m_Done; }                    //[t3]
00152 
00154   Cursor &operator+=(size_type N) { Move(N); return *this;}             //[t19]
00156   Cursor &operator-=(size_type N) { Move(-N); return *this;}            //[t19]
00157 
00159 
00170   size_type size() const throw () { return m_Size; }
00171 
00173 
00180   size_type Pos() const throw (unknown_position)                        //[t43]
00181   { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00182 
00183 
00184 private:
00185   static PGSTD::string OffsetString(size_type);
00186   PGSTD::string MakeFetchCmd(size_type) const;
00187   size_type NormalizedMove(size_type Intended, size_type Actual);
00188 
00189   TransactionItf &m_Trans;
00190   PGSTD::string m_Name;
00191   size_type m_Count;
00192   bool m_Done;
00193   size_type m_Pos;
00194   size_type m_Size;
00195 
00196   // Not allowed:
00197   Cursor(const Cursor &);
00198   Cursor &operator=(const Cursor &);
00199 };
00200 
00201 }
00202 
00203 #endif
00204 

Generated on Thu Jan 2 20:15:21 2003 for libpqxx by doxygen1.3-rc2