22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
31 #include "pqxx/except"
32 #include "pqxx/strconv"
70 const PGSTD::string &,
83 class result_connection;
84 class result_creation;
85 class result_sql_cursor;
113 const internal::result_data, internal::freemem_result_data>
154 m_Home(r), m_Index(i), m_Begin(0), m_End(r ? r->columns() : 0) {}
162 bool operator==(
const tuple &)
const throw ();
163 bool operator!=(const
tuple &rhs) const throw ()
164 {
return !operator==(rhs); }
183 {
return field(*
this, m_Begin+i); }
195 {
return at(s.c_str()); }
200 void swap(
tuple &) throw ();
209 size_type column_number(
const PGSTD::string &ColName)
const
213 size_type column_number(
const char[])
const;
217 {
return m_Home->column_type(m_Begin+ColNum); }
220 oid column_type(
int ColNum)
const
224 oid column_type(
const PGSTD::string &ColName)
const
228 oid column_type(
const char ColName[])
const
240 {
return m_Home->column_table(m_Begin+ColNum); }
249 oid column_table(
int ColNum)
const
259 oid column_table(
const PGSTD::string &ColName)
const
274 {
return m_Home->table_column(m_Begin+ColNum); }
281 size_type table_column(
const PGSTD::string &ColName)
const
302 bool empty()
const throw ();
320 class PQXX_LIBEXPORT field
331 m_tup(T), m_col(C) {}
354 bool operator==(
const field &)
const;
359 bool operator!=(
const field &rhs)
const {
return !operator==(rhs);}
367 const char *
name()
const {
return home()->column_name(col()); }
370 oid type()
const {
return home()->column_type(col()); }
380 oid table()
const {
return home()->column_table(col()); }
386 {
return home()->table_column(col()); }
399 const char *
c_str()
const {
return home()->GetValue(idx(),col()); }
402 template<
typename T>
bool to(T &Obj)
const
404 const char *
const bytes = c_str();
405 if (!bytes[0] && is_null())
return false;
411 template<
typename T>
bool operator>>(T &Obj)
const
414 #ifdef PQXX_NO_PARTIAL_CLASS_TEMPLATE_SPECIALISATION
416 template<>
bool to<PGSTD::string>(PGSTD::string &Obj)
const;
422 template<>
bool to<const char *>(
const char *&Obj)
const;
426 template<
typename T>
bool to(T &Obj,
const T &Default)
const
428 const bool NotNull = to(Obj);
429 if (!NotNull) Obj = Default;
437 template<
typename T> T as(
const T &Default)
const
445 template<
typename T> T as() const
448 const bool NotNull = to(Obj);
453 bool is_null()
const {
return home()->GetIsNull(idx(), col()); }
454 size_type size()
const throw ()
455 {
return home()->GetLength(idx(),col()); }
460 const result *home()
const throw () {
return m_tup.m_Home; }
469 typedef PGSTD::iterator<PGSTD::random_access_iterator_tag,
533 {
return m_Index==i.m_Index;}
535 {
return m_Index!=i.m_Index;}
537 {
return m_Index<i.m_Index;}
539 {
return m_Index<=i.m_Index;}
541 {
return m_Index>i.m_Index;}
543 {
return m_Index>=i.m_Index;}
570 using iterator_type::iterator_category;
574 using iterator_type::value_type;
579 typedef tuple value_type;
587 iterator_type base()
const throw ();
602 { iterator_type::operator=(r);
return *
this; }
604 { iterator_type::operator--();
return *
this; }
607 { iterator_type::operator++();
return *
this; }
610 { iterator_type::operator-=(i);
return *
this; }
612 { iterator_type::operator+=(i);
return *
this; }
624 {
return rhs.const_iterator::operator-(*this); }
632 {
return iterator_type::operator==(rhs); }
634 {
return !operator==(rhs); }
637 {
return iterator_type::operator>(rhs); }
639 {
return iterator_type::operator>=(rhs); }
641 {
return iterator_type::operator<(rhs); }
643 {
return iterator_type::operator<=(rhs); }
650 public PGSTD::iterator<PGSTD::random_access_iterator_tag,
655 typedef PGSTD::iterator<PGSTD::random_access_iterator_tag,
696 {
return col()==i.col();}
698 {
return col()!=i.col();}
700 {
return col()<i.col();}
702 {
return col()<=i.col();}
704 {
return col()>i.col();}
706 {
return col()>=i.col();}
728 using iterator_type::iterator_category;
730 using iterator_type::pointer;
732 using iterator_type::value_type;
736 typedef field value_type;
746 iterator_type base()
const throw ();
752 using iterator_type::operator->;
753 using iterator_type::operator*;
762 { iterator_type::operator=(r);
return *
this; }
764 { iterator_type::operator--();
return *
this; }
767 { iterator_type::operator++();
return *
this; }
770 { iterator_type::operator-=(i);
return *
this; }
772 { iterator_type::operator+=(i);
return *
this; }
785 {
return rhs.const_fielditerator::operator-(*this); }
794 {
return iterator_type::operator==(rhs); }
797 {
return !operator==(rhs); }
800 {
return iterator_type::operator>(rhs); }
802 {
return iterator_type::operator>=(rhs); }
804 {
return iterator_type::operator<(rhs); }
806 {
return iterator_type::operator<=(rhs); }
813 super(rhs), m_data(rhs.m_data) {}
816 { super::operator=(rhs); m_data=rhs.m_data;
return *
this; }
822 bool operator==(
const result &)
const throw ();
823 bool operator!=(const
result &rhs) const throw ()
824 {
return !operator==(rhs); }
834 inline const_iterator end()
const throw ();
836 reference front() const throw () {
return tuple(
this,0); }
839 size_type size()
const throw ();
840 bool empty() const throw ();
841 size_type capacity() const throw () {
return size(); }
843 void swap(
result &) throw ();
845 const tuple operator[](size_type i) const throw ()
846 {
return tuple(
this, i); }
847 const tuple at(size_type)
const throw (
range_error);
849 void clear() throw () { super::reset(); m_data = 0; }
856 tuple::size_type columns()
const throw ();
859 tuple::size_type column_number(const
char ColName[]) const;
862 tuple::size_type column_number(const PGSTD::
string &Name) const
866 const char *column_name(tuple::size_type Number)
const;
869 oid column_type(tuple::size_type ColNum)
const;
871 oid column_type(
int ColNum)
const
875 oid column_type(
const PGSTD::string &ColName)
const
879 oid column_type(
const char ColName[])
const
890 oid column_table(tuple::size_type ColNum)
const;
900 oid column_table(
int ColNum)
const
911 oid column_table(
const PGSTD::string &ColName)
const
915 tuple::size_type table_column(tuple::size_type ColNum)
const;
927 const PGSTD::string &query()
const throw ();
933 oid inserted_oid() const;
940 size_type affected_rows() const;
945 const
char *GetValue(size_type Row, tuple::size_type Col) const;
946 bool GetIsNull(size_type Row, tuple::size_type Col) const;
947 field::size_type GetLength(size_type, tuple::size_type) const throw ();
949 friend class pqxx::internal::gate::result_creation;
950 result(internal::pq::PGresult *rhs,
952 const PGSTD::
string &Query,
954 void PQXX_PRIVATE CheckStatus() const;
956 friend class pqxx::internal::gate::result_connection;
957 bool operator!() const throw () {
return !m_data; }
958 operator bool()
const throw () {
return m_data != 0; }
960 void PQXX_PRIVATE ThrowSQLError(
const PGSTD::string &Err,
961 const PGSTD::string &Query)
const;
962 int PQXX_PRIVATE errorposition()
const throw ();
963 PGSTD::
string PQXX_PRIVATE StatusError() const;
965 friend class pqxx::internal::gate::result_sql_cursor;
966 const
char *CmdStatus() const throw ();
969 pqxx::internal::pq::PGresult *m_data;
971 static const PGSTD::
string PQXX_PRIVATE s_empty_string;
996 template<typename CHAR>
997 inline PGSTD::basic_ostream<CHAR> &operator<<(
998 PGSTD::basic_ostream<CHAR> &S, const pqxx::
result::field &F)
1000 S.write(F.c_str(), F.size());
1006 template<
typename T>
1013 {
return PGSTD::string(Obj.
c_str(), Obj.
size()); }
1018 inline bool result::field::to<PGSTD::string>(PGSTD::string &Obj)
const
1020 const char *
const bytes = c_str();
1021 if (!bytes[0] && is_null())
return false;
1022 Obj = PGSTD::string(bytes, size());
1033 inline bool result::field::to<const char *>(
const char *&Obj)
const
1035 if (is_null())
return false;
1056 inline result::const_iterator
1075 inline result::const_fielditerator
1086 inline result::const_fielditerator
1097 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
1099 #ifdef PQXX_HAVE_STREAMBUF
1100 public PGSTD::basic_streambuf<CHAR, TRAITS>
1102 public PGSTD::streambuf
1109 #ifdef PQXX_HAVE_STREAMBUF
1110 typedef typename traits_type::pos_type
pos_type;
1111 typedef typename traits_type::off_type
off_type;
1125 #ifdef PQXX_HAVE_STREAMBUF
1128 virtual int sync() {
return traits_type::eof(); }
1132 {
return traits_type::eof(); }
1140 int_type initialize()
1143 reinterpret_cast<char_type *
>(
const_cast<char *
>(m_Field.c_str()));
1144 this->setg(G, G, G + m_Field.size());
1145 return int_type(m_Field.size());
1159 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
1161 #ifdef PQXX_HAVE_STREAMBUF
1162 public PGSTD::basic_istream<CHAR, TRAITS>
1164 public PGSTD::istream
1167 #ifdef PQXX_HAVE_STREAMBUF
1168 typedef PGSTD::basic_istream<CHAR, TRAITS> super;
1170 typedef PGSTD::istream super;
1181 { super::init(&m_Buf); }
1207 #include "pqxx/compiler-internal-post.hxx"