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 
00058 class PQXX_LIBEXPORT Cursor
00059 {
00060 public:
00061   // TODO: This apparently being migrated from int to long in Postgres.
00062   typedef Result::size_type size_type;
00063 
00064   enum pos { pos_unknown = -1, pos_start = 0 };
00065 
00067   struct unknown_position : PGSTD::runtime_error
00068   {
00069     unknown_position(const PGSTD::string &cursorname) :                 //[]
00070       PGSTD::runtime_error("Position for cursor '" + cursorname + "' "
00071                            "is unknown") 
00072     {
00073     }
00074   };
00075 
00077 
00085   Cursor(TransactionItf &T,
00086          const char Query[], 
00087          const PGSTD::string &BaseName="cur",
00088          size_type Count=NEXT());                                       //[t3]
00089 
00091 
00121   Cursor(TransactionItf &T,
00122          const Result::Field &Name,
00123          size_type Count=NEXT());                                       //[t45]
00124 
00126   size_type SetCount(size_type);                                        //[t19]
00127 
00129 
00138   Result Fetch(size_type Count);                                        //[t19]
00139 
00141 
00149   size_type Move(size_type Count);                                      //[t42]
00150 
00151   void MoveTo(size_type);                                               //[t44]
00152 
00154 
00158   static size_type ALL() throw ()                                       //[t3]
00159         { return PGSTD::numeric_limits<Result::size_type>::max(); }
00160 
00162   static size_type NEXT() throw () { return 1; }                        //[t19]
00163 
00165   static size_type PRIOR() throw () { return -1; }                      //[t19]
00166 
00169 
00173   static size_type BACKWARD_ALL() throw ()                              //[t19]
00174         { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00175 
00177 
00184   Cursor &operator>>(Result &);                                         //[t3]
00185 
00187   operator bool() const throw () { return !m_Done; }                    //[t3]
00189   bool operator!() const throw () { return m_Done; }                    //[t3]
00190 
00192   Cursor &operator+=(size_type N) { Move(N); return *this;}             //[t19]
00194   Cursor &operator-=(size_type N) { Move(-N); return *this;}            //[t19]
00195 
00197 
00208   size_type size() const throw () { return m_Size; }                    //[t44]
00209 
00211 
00218   size_type Pos() const throw (unknown_position)                        //[t43]
00219   { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00220 
00221 
00222 private:
00223   static PGSTD::string OffsetString(size_type);
00224   PGSTD::string MakeFetchCmd(size_type) const;
00225   size_type NormalizedMove(size_type Intended, size_type Actual);
00226 
00227   TransactionItf &m_Trans;
00228   PGSTD::string m_Name;
00229   size_type m_Count;
00230   bool m_Done;
00231   size_type m_Pos;
00232   size_type m_Size;
00233 
00234   // Not allowed:
00235   Cursor(const Cursor &);
00236   Cursor &operator=(const Cursor &);
00237 };
00238 
00239 }
00240 
00241 #endif
00242 

Generated on Fri Feb 28 19:23:32 2003 for libpqxx by doxygen1.3-rc3