00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pqxx/compiler-public.hxx"
00020 #include "pqxx/compiler-internal-pre.hxx"
00021
00022 #include "pqxx/result"
00023 #include "pqxx/tablestream"
00024
00025
00026
00027
00028 namespace pqxx
00029 {
00030
00032
00046 class PQXX_LIBEXPORT tablereader : public tablestream
00047 {
00048 public:
00049 tablereader(transaction_base &,
00050 const PGSTD::string &Name,
00051 const PGSTD::string &Null=PGSTD::string());
00052
00054
00056 template<typename ITER>
00057 tablereader(transaction_base &,
00058 const PGSTD::string &Name,
00059 ITER begincolumns,
00060 ITER endcolumns);
00061
00062 template<typename ITER> tablereader(transaction_base &,
00063 const PGSTD::string &Name,
00064 ITER begincolumns,
00065 ITER endcolumns,
00066 const PGSTD::string &Null);
00067
00068 ~tablereader() throw ();
00069
00070 template<typename TUPLE> tablereader &operator>>(TUPLE &);
00071
00072 operator bool() const throw () { return !m_Done; }
00073 bool operator!() const throw () { return m_Done; }
00074
00076
00080 bool get_raw_line(PGSTD::string &Line);
00081
00082 template<typename TUPLE>
00083 void tokenize(PGSTD::string, TUPLE &) const;
00084
00086
00093 virtual void complete();
00094
00095 private:
00096 void setup(transaction_base &T,
00097 const PGSTD::string &RName,
00098 const PGSTD::string &Columns=PGSTD::string());
00099 void PQXX_PRIVATE reader_close();
00100 PGSTD::string extract_field(const PGSTD::string &,
00101 PGSTD::string::size_type &) const;
00102
00103 bool m_Done;
00104 };
00105
00106
00107
00108
00109
00110 template<typename ITER> inline
00111 tablereader::tablereader(transaction_base &T,
00112 const PGSTD::string &Name,
00113 ITER begincolumns,
00114 ITER endcolumns) :
00115 namedclass(Name, "tablereader"),
00116 tablestream(T, PGSTD::string()),
00117 m_Done(true)
00118 {
00119 setup(T, Name, columnlist(begincolumns, endcolumns));
00120 }
00121
00122 template<typename ITER> inline
00123 tablereader::tablereader(transaction_base &T,
00124 const PGSTD::string &Name,
00125 ITER begincolumns,
00126 ITER endcolumns,
00127 const PGSTD::string &Null) :
00128 namedclass(Name, "tablereader"),
00129 tablestream(T, Null),
00130 m_Done(true)
00131 {
00132 setup(T, Name, columnlist(begincolumns, endcolumns));
00133 }
00134
00135
00136 template<typename TUPLE>
00137 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00138 {
00139 PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00140
00141
00142 PGSTD::string::size_type here=0;
00143 while (here < Line.size()) *ins++ = extract_field(Line, here);
00144 }
00145
00146
00147 template<typename TUPLE>
00148 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00149 {
00150 PGSTD::string Line;
00151 if (get_raw_line(Line)) tokenize(Line, T);
00152 return *this;
00153 }
00154
00155
00156 }
00157
00158 #include "pqxx/compiler-internal-post.hxx"