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 
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 
00076   // TODO: Allow usage of SCROLL ("DECLARE foo SCROLL CURSOR FOR ...")
00078   /** 
00079    * @param T is the transaction that this cursor lives in.
00080    * @param Query defines a data set that the cursor should traverse.
00081    * @param BaseName optional name for the cursor, must begin with a letter 
00082    * and contain letters and digits only.  
00083    * @param Count the stride of the cursor, ie. the number of rows fetched at a
00084    * time.  This defaults to 1.
00085    */
00086   Cursor(TransactionItf &T,
00087          const char Query[], 
00088          const PGSTD::string &BaseName="cur",
00089          size_type Count=NEXT());                                       //[t3]
00090 
00092 
00122   Cursor(TransactionItf &T,
00123          const Result::Field &Name,
00124          size_type Count=NEXT());                                       //[t45]
00125 
00127   size_type SetCount(size_type);                                        //[t19]
00128 
00130 
00139   Result Fetch(size_type Count);                                        //[t19]
00140 
00142 
00150   size_type Move(size_type Count);                                      //[t42]
00151 
00152   void MoveTo(size_type);                                               //[t44]
00153 
00155 
00159   static size_type ALL() throw ()                                       //[t3]
00160         { return PGSTD::numeric_limits<Result::size_type>::max(); }
00161 
00163   static size_type NEXT() throw () { return 1; }                        //[t19]
00164 
00166   static size_type PRIOR() throw () { return -1; }                      //[t19]
00167 
00170 
00174   static size_type BACKWARD_ALL() throw ()                              //[t19]
00175         { return PGSTD::numeric_limits<Result::size_type>::min() + 1; }
00176 
00178 
00185   Cursor &operator>>(Result &);                                         //[t3]
00186 
00188   operator bool() const throw () { return !m_Done; }                    //[t3]
00190   bool operator!() const throw () { return m_Done; }                    //[t3]
00191 
00193   Cursor &operator+=(size_type N) { Move(N); return *this;}             //[t19]
00195   Cursor &operator-=(size_type N) { Move(-N); return *this;}            //[t19]
00196 
00198 
00209   size_type size() const throw () { return m_Size; }                    //[t44]
00210 
00212 
00219   size_type Pos() const throw (unknown_position)                        //[t43]
00220   { if (m_Pos==pos_unknown) throw unknown_position(m_Name); return m_Pos; }
00221 
00222 
00223 private:
00224   static PGSTD::string OffsetString(size_type);
00225   PGSTD::string MakeFetchCmd(size_type) const;
00226   size_type NormalizedMove(size_type Intended, size_type Actual);
00227 
00228   TransactionItf &m_Trans;
00229   PGSTD::string m_Name;
00230   size_type m_Count;
00231   bool m_Done;
00232   size_type m_Pos;
00233   size_type m_Size;
00234 
00235   // Not allowed:
00236   Cursor(const Cursor &);
00237   Cursor &operator=(const Cursor &);
00238 };
00239 
00240 }
00241 
00242 #endif
00243 

Generated on Mon Apr 28 16:37:18 2003 for libpqxx by doxygen1.3-rc3