16#if !defined(PQXX_HEADER_PRE)
17# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
22#include "pqxx/array.hxx"
23#include "pqxx/composite.hxx"
24#include "pqxx/result.hxx"
25#include "pqxx/strconv.hxx"
26#include "pqxx/types.hxx"
67 return not operator==(
rhs);
113 return std::string_view(c_str(), size());
149 auto const data{c_str()};
190 (
not std::is_pointer<T>::value
or std::is_same<T, char const *>::value),
219 template<
typename T> T
as()
const
238 template<
typename T,
template<
typename>
class O = std::optional>
267 "Do not construct fields yourself. Get them from the "
297template<>
inline bool field::to<std::string>(std::string &
obj)
const
301 obj = std::string{view()};
307inline bool field::to<std::string>(
314 obj = std::string{view()};
325template<>
inline bool field::to<char const *>(
char const *&
obj)
const
334template<>
inline bool field::to<std::string_view>(std::string_view &
obj)
const
344inline bool field::to<std::string_view>(
356template<>
inline std::string_view field::as<std::string_view>()
const
366inline std::string_view
367field::as<std::string_view>(std::string_view
const &
default_value)
const
373template<>
inline bool field::to<zview>(
zview &
obj)
const
394template<>
inline zview field::as<zview>()
const
409template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
424 virtual int sync()
override {
return traits_type::eof(); }
428 return traits_type::eof();
432 return traits_type::eof();
438 field const &m_field;
443 this->
setg(
g,
g,
g + std::size(m_field));
444 return int_type(std::size(m_field));
463template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
466 using super = std::basic_istream<CHAR, TRAITS>;
516template<
typename CHAR>
518 "Do this by hand, probably with better error checking.")]]
inline std::
519 basic_ostream<CHAR> &
522 s.write(value.
c_str(), std::streamsize(std::size(value)));
559 "Extracting non-null field into nullptr_t variable."};
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
std::basic_ostream< CHAR > & operator<<(std::basic_ostream< CHAR > &s, field const &value)
Write a result field to any type of stream.
Definition field.hxx:520
std::size_t field_size_type
Number of bytes in a field of database data.
Definition types.hxx:40
int result_size_type
Number of rows in a result set.
Definition types.hxx:28
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition strconv.hxx:557
int row_size_type
Number of fields in a row of database data.
Definition types.hxx:34
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition strconv.hxx:513
void parse_composite(pqxx::internal::encoding_group enc, std::string_view text, T &...fields)
Parse a string representation of a value of a composite type.
Definition composite.hxx:35
std::nullptr_t from_string< std::nullptr_t >(field const &value)
Convert a field's value to nullptr_t.
Definition field.hxx:555
std::string to_string(field const &value)
Convert a field to a string.
Definition result.cxx:566
T from_string(field const &value)
Convert a field's value to type T.
Definition field.hxx:531
void PQXX_COLD throw_null_conversion(std::string const &type)
Definition strconv.cxx:253
Low-level array parser.
Definition array.hxx:527
Value conversion failed, e.g. when converting "Hello" to int.
Definition except.hxx:283
Reference to a field in a result set.
Definition field.hxx:35
PQXX_PURE size_type size() const noexcept
Return number of bytes taken up by the field's value.
Definition field.cxx:77
T as(T const &default_value) const
Return value as object of given type, or default value if null.
Definition field.hxx:205
row_size_type m_col
Definition field.hxx:289
array_parser as_array() const &noexcept
Parse the field as an SQL array.
Definition field.hxx:251
auto to(T &obj, T const &default_value) const -> typename std::enable_if_t<(not std::is_pointer< T >::value or std::is_same< T, char const * >::value), bool >
Read value into obj; or if null, use default value and return false.
Definition field.hxx:189
field_size_type size_type
Definition field.hxx:37
bool operator>>(T &obj) const
Read value into obj; or leave obj untouched and return false if null.
Definition field.hxx:175
PQXX_PURE bool operator!=(field const &rhs) const noexcept
Byte-by-byte comparison (all nulls are considered equal)
Definition field.hxx:65
PQXX_PURE char const * c_str() const &
Read as plain C string.
Definition field.cxx:65
T as() const
Return value as object of given type, or throw exception if null.
Definition field.hxx:219
field(result const &r, result_size_type row_num, row_size_type col_num) noexcept
Definition field.hxx:279
constexpr row_size_type col() const noexcept
Definition field.hxx:274
PQXX_PURE std::string_view view() const &
Read as string_view, or an empty one if null.
Definition field.hxx:111
bool composite_to(T &...fields) const
Read field as a composite value, write its components into fields.
Definition field.hxx:161
field() noexcept=default
Constructor. Do not call this yourself; libpqxx will do it for you.
PQXX_PURE bool is_null() const noexcept
Is this field's value null?
Definition field.cxx:71
constexpr O< T > get() const
Return value wrapped in some optional type (empty for nulls).
Definition field.hxx:239
constexpr result::size_type idx() const noexcept
Definition field.hxx:273
TRAITS traits_type
Definition field.hxx:414
typename traits_type::off_type off_type
Definition field.hxx:417
field_streambuf(field const &f)
Definition field.hxx:421
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition field.hxx:426
virtual pos_type seekpos(pos_type, openmode) override
Definition field.hxx:430
std::ios::openmode openmode
Definition field.hxx:418
virtual int_type overflow(int_type) override
Definition field.hxx:434
typename traits_type::pos_type pos_type
Definition field.hxx:416
virtual int sync() override
Definition field.hxx:424
typename traits_type::int_type int_type
Definition field.hxx:415
virtual int_type underflow() override
Definition field.hxx:435
CHAR char_type
Definition field.hxx:413
std::ios::seekdir seekdir
Definition field.hxx:419
Input stream that gets its data from a result field.
Definition field.hxx:465
TRAITS traits_type
Definition field.hxx:470
basic_fieldstream(field const &f)
Definition field.hxx:475
typename traits_type::pos_type pos_type
Definition field.hxx:472
typename traits_type::off_type off_type
Definition field.hxx:473
typename traits_type::int_type int_type
Definition field.hxx:471
CHAR char_type
Definition field.hxx:469
Result set containing data returned by a query or command.
Definition result.hxx:73
result_size_type size_type
Definition result.hxx:75
Reference to one row in a result.
Definition row.hxx:47
Traits describing a type's "null value," if any.
Definition strconv.hxx:91
static TYPE null()
Return a null value.
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38