Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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-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 
00056 class PQXX_LIBEXPORT Cursor
00057 {
00058 public:
00059   // TODO: This apparently being migrated from int to long in Postgres.
00060   typedef Result::size_type size_type;
00061 
00062   enum pos { pos_unknown = -1, pos_start = 0 };
00063 
00065   struct unknown_position : PGSTD::runtime_error
00066   {
00067     unknown_position(const PGSTD::string &cursorname) :                 //[]
00068       PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00069                            "is unknown") 
00070     {
00071     }
00072   };
00073 
00075 
00083   Cursor(TransactionItf &T,
00084          const char Query[], 
00085          const PGSTD::string &BaseName="cur",
00086          size_type Count=NEXT());                                       //[t3]
00087 
00089   size_type SetCount(size_type);                                        //[t19]
00090 
00092 
00101   Result Fetch(size_type Count);                                        //[t19]
00102 
00104 
00112   size_type Move(size_type Count);                                      //[t42]
00113 
00114   void MoveTo(size_type);                                               //[t44]
00115 
00117 
00121   static size_type ALL() throw ()                                       //[t3]
00122         { return PGSTD::numeric_limits<Result::size_type>::max(); }
00123 
00125   static size_type NEXT() throw () { return 1; }                        //[t19]
00126 
00128   static size_type PRIOR() throw () { return -1; }                      //[t19]
00129 
00132 
00136   static size_type BACKWARD_ALL() throw ()                              //[t19]
00137         { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00138 
00140 
00147   Cursor &operator>>(Result &);                                         //[t3]
00148 
00150   operator bool() const throw () { return !m_Done; }                    //[t3]
00152   bool operator!() const throw () { return m_Done; }                    //[t3]
00153 
00155   Cursor &operator+=(size_type N) { Move(N); return *this;}             //[t19]
00157   Cursor &operator-=(size_type N) { Move(-N); return *this;}            //[t19]
00158 
00160 
00171   size_type size() const throw () { return m_Size; }                    //[t44]
00172 
00174 
00181   size_type Pos() const throw (unknown_position)                        //[t43]
00182   { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00183 
00184 
00185 private:
00186   static PGSTD::string OffsetString(size_type);
00187   PGSTD::string MakeFetchCmd(size_type) const;
00188   size_type NormalizedMove(size_type Intended, size_type Actual);
00189 
00190   TransactionItf &m_Trans;
00191   PGSTD::string m_Name;
00192   size_type m_Count;
00193   bool m_Done;
00194   size_type m_Pos;
00195   size_type m_Size;
00196 
00197   // Not allowed:
00198   Cursor(const Cursor &);
00199   Cursor &operator=(const Cursor &);
00200 };
00201 
00202 }
00203 
00204 #endif
00205 

Generated on Tue Feb 11 12:56:39 2003 for libpqxx by doxygen1.3-rc2