16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/compiler-internal-pre.hxx" 19 #if defined(PQXX_HAVE_OPTIONAL) 30 #elif defined(PQXX_HAVE_EXP_OPTIONAL) && !defined(PQXX_HIDE_EXP_OPTIONAL) 31 #include <experimental/optional> 34 #include "pqxx/array.hxx" 35 #include "pqxx/result.hxx" 36 #include "pqxx/strconv.hxx" 37 #include "pqxx/types.hxx" 81 bool operator==(
const field &)
const;
87 {
return !operator==(rhs);}
94 const char *name()
const;
119 const char *c_str()
const;
122 bool is_null()
const noexcept;
131 template<
typename T>
bool to(T &Obj)
const 133 const char *
const bytes = c_str();
134 if (!bytes[0] && is_null())
return false;
144 template<
typename T>
bool to(T &Obj,
const T &Default)
const 146 const bool NotNull = to(Obj);
147 if (!NotNull) Obj = Default;
155 template<
typename T> T
as(
const T &Default)
const 163 template<
typename T> T
as() const
166 const bool NotNull = to(Obj);
171 #if defined(PQXX_HAVE_OPTIONAL) 172 template<
typename T> std::optional<T>
get()
const 174 {
return get_opt<T, std::optional<T>>(); }
175 #elif defined(PQXX_HAVE_EXP_OPTIONAL) && !defined(PQXX_HIDE_EXP_OPTIONAL) 176 template<
typename T> std::experimental::optional<T>
get()
const 178 {
return get_opt<T, std::experimental::optional<T>>(); }
194 size_t idx() const noexcept {
return m_row; }
210 template<
typename T,
typename OPTIONAL_T> OPTIONAL_T get_opt()
const 212 if (is_null())
return OPTIONAL_T();
213 else return OPTIONAL_T(as<T>());
223 inline bool field::to<std::string>(std::string &Obj)
const 225 const char *
const bytes = c_str();
226 if (!bytes[0] && is_null())
return false;
227 Obj = std::string(bytes, size());
238 inline bool field::to<const char *>(
const char *&Obj)
const 240 if (is_null())
return false;
246 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
248 public std::basic_streambuf<CHAR, TRAITS>
266 virtual int sync()
override {
return traits_type::eof(); }
270 {
return traits_type::eof(); }
272 {
return traits_type::eof();}
274 {
return traits_type::eof(); }
276 {
return traits_type::eof(); }
279 const field &m_field;
284 reinterpret_cast<char_type *
>(
const_cast<char *
>(m_field.
c_str()));
285 this->setg(G, G, G + m_field.
size());
300 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
302 public std::basic_istream<CHAR, TRAITS>
304 using super = std::basic_istream<CHAR, TRAITS>;
309 using int_type =
typename traits_type::int_type;
314 { super::init(&m_buf); }
343 template<
typename CHAR>
345 std::basic_ostream<CHAR> &S,
const field &F)
347 S.write(F.
c_str(), std::streamsize(F.
size()));
358 template<> PQXX_LIBEXPORT std::string
to_string(
const field &Obj);
361 #include "pqxx/compiler-internal-post.hxx" TRAITS traits_type
Definition: field.hxx:252
size_t idx() const noexcept
Definition: field.hxx:194
bool to(T &Obj, const T &Default) const
Read value into Obj; or use Default & return false if null.
Definition: field.hxx:144
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:163
unsigned int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:24
Result set containing data returned by a query or command.
Definition: result.hxx:65
field_streambuf(const field &F)
Definition: field.hxx:259
row_size_type col() const noexcept
Definition: field.hxx:195
typename traits_type::int_type int_type
Definition: field.hxx:253
CHAR char_type
Definition: field.hxx:307
const result & home() const noexcept
Definition: field.hxx:193
std::ios::openmode openmode
Definition: field.hxx:256
TRAITS traits_type
Definition: field.hxx:308
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
Reference to one row in a result.
Definition: row.hxx:40
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:354
typename traits_type::off_type off_type
Definition: field.hxx:311
std::ios::seekdir seekdir
Definition: field.hxx:257
std::basic_ostream< CHAR > & operator<<(std::basic_ostream< CHAR > &S, const field &F)
Write a result field to any type of stream.
Definition: field.hxx:344
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:269
size_type size() const noexcept
Return number of bytes taken up by the field's value.
Definition: field.cxx:74
Input stream that gets its data from a result field.
Definition: field.hxx:301
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:271
const char * c_str() const
Read as plain C string.
Definition: field.cxx:62
field_size_type size_type
Definition: field.hxx:51
row_size_type num() const
Definition: field.hxx:103
T as(const T &Default) const
Return value as object of given type, or Default if null.
Definition: field.hxx:155
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
basic_fieldstream(const field &F)
Definition: field.hxx:313
std::size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:30
typename traits_type::pos_type pos_type
Definition: field.hxx:254
long m_col
Definition: field.hxx:201
Definition: field.hxx:247
bool operator>>(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:140
bool operator!=(const field &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:86
typename traits_type::off_type off_type
Definition: field.hxx:255
Reference to a field in a result set.
Definition: field.hxx:48
virtual int_type overflow(int_type) override
Definition: field.hxx:273
Traits class for use in string conversions.
Definition: strconv.hxx:52
typename traits_type::pos_type pos_type
Definition: field.hxx:310
bool to(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:131
virtual int_type underflow() override
Definition: field.hxx:275
CHAR char_type
Definition: field.hxx:251
virtual int sync() override
Definition: field.hxx:266
Low-level array parser.
Definition: array.hxx:43
array_parser as_array() const
Parse the field as an SQL array.
Definition: field.hxx:188