libpqxx 4.0
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * FILE 00004 * pqxx/tablereader.hxx 00005 * 00006 * DESCRIPTION 00007 * definition of the pqxx::tablereader class. 00008 * pqxx::tablereader enables optimized batch reads from a database table 00009 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/tablereader instead. 00010 * 00011 * Copyright (c) 2001-2011, Jeroen T. Vermeulen <jtv@xs4all.nl> 00012 * 00013 * See COPYING for copyright license. If you did not receive a file called 00014 * COPYING with this source code, please notify the distributor of this mistake, 00015 * or contact the author. 00016 * 00017 *------------------------------------------------------------------------- 00018 */ 00019 #ifndef PQXX_H_TABLEREADER 00020 #define PQXX_H_TABLEREADER 00021 #include "pqxx/compiler-public.hxx" 00022 #include "pqxx/compiler-internal-pre.hxx" 00023 #include "pqxx/result" 00024 #include "pqxx/tablestream" 00025 namespace pqxx 00026 { 00028 00031 class PQXX_LIBEXPORT tablereader : public tablestream 00032 { 00033 public: 00034 tablereader(transaction_base &, 00035 const PGSTD::string &Name, 00036 const PGSTD::string &Null=PGSTD::string()); 00037 template<typename ITER> 00038 tablereader(transaction_base &, 00039 const PGSTD::string &Name, 00040 ITER begincolumns, 00041 ITER endcolumns); 00042 template<typename ITER> tablereader(transaction_base &, 00043 const PGSTD::string &Name, 00044 ITER begincolumns, 00045 ITER endcolumns, 00046 const PGSTD::string &Null); 00047 ~tablereader() throw (); 00048 template<typename TUPLE> tablereader &operator>>(TUPLE &); 00049 operator bool() const throw () { return !m_Done; } 00050 bool operator!() const throw () { return m_Done; } 00051 bool get_raw_line(PGSTD::string &Line); 00052 template<typename TUPLE> 00053 void tokenize(PGSTD::string, TUPLE &) const; 00054 virtual void complete(); 00055 private: 00056 void setup(transaction_base &T, 00057 const PGSTD::string &RName, 00058 const PGSTD::string &Columns=PGSTD::string()); 00059 void PQXX_PRIVATE reader_close(); 00060 PGSTD::string extract_field(const PGSTD::string &, 00061 PGSTD::string::size_type &) const; 00062 bool m_Done; 00063 }; 00064 template<typename ITER> inline 00065 tablereader::tablereader(transaction_base &T, 00066 const PGSTD::string &Name, 00067 ITER begincolumns, 00068 ITER endcolumns) : 00069 namedclass(Name, "tablereader"), 00070 tablestream(T, PGSTD::string()), 00071 m_Done(true) 00072 { 00073 setup(T, Name, columnlist(begincolumns, endcolumns)); 00074 } 00075 template<typename ITER> inline 00076 tablereader::tablereader(transaction_base &T, 00077 const PGSTD::string &Name, 00078 ITER begincolumns, 00079 ITER endcolumns, 00080 const PGSTD::string &Null) : 00081 namedclass(Name, "tablereader"), 00082 tablestream(T, Null), 00083 m_Done(true) 00084 { 00085 setup(T, Name, columnlist(begincolumns, endcolumns)); 00086 } 00087 template<typename TUPLE> 00088 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const 00089 { 00090 PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T); 00091 PGSTD::string::size_type here=0; 00092 while (here < Line.size()) *ins++ = extract_field(Line, here); 00093 } 00094 template<typename TUPLE> 00095 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T) 00096 { 00097 PGSTD::string Line; 00098 if (get_raw_line(Line)) tokenize(Line, T); 00099 return *this; 00100 } 00101 } // namespace pqxx 00102 #include "pqxx/compiler-internal-post.hxx" 00103 #endif