16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 21 #include "pqxx/array.hxx" 22 #include "pqxx/composite.hxx" 23 #include "pqxx/result.hxx" 24 #include "pqxx/strconv.hxx" 25 #include "pqxx/types.hxx" 68 [[nodiscard]] PQXX_PURE
bool operator==(
field const &)
const;
75 return not operator==(rhs);
83 [[nodiscard]] PQXX_PURE
char const *name()
const;
87 [[nodiscard]] oid PQXX_PURE type()
const;
90 [[nodiscard]] PQXX_PURE oid table()
const;
102 [[nodiscard]] PQXX_PURE std::string_view view()
const 105 return std::string_view(c_str(), size());
118 [[nodiscard]] PQXX_PURE
char const *c_str()
const;
121 [[nodiscard]] PQXX_PURE
bool is_null()
const noexcept;
124 [[nodiscard]] PQXX_PURE
size_type size()
const noexcept;
131 auto to(T &obj)
const ->
typename std::enable_if_t<
132 (not std::is_pointer<T>::value or std::is_same<T, char const *>::value),
141 auto const bytes{c_str()};
167 template<
typename T>
bool operator>>(T &obj)
const {
return to(obj); }
181 auto to(T &obj, T
const &default_value)
const ->
typename std::enable_if_t<
182 (not std::is_pointer<T>::value or std::is_same<T, char const *>::value),
189 obj = from_string<T>(this->view());
197 template<
typename T> T
as(T
const &default_value)
const 200 return default_value;
202 return from_string<T>(this->view());
211 template<
typename T> T
as()
const 226 return from_string<T>(this->view());
234 template<
typename T,
template<
typename>
class O = std::optional>
235 constexpr O<T>
get()
const 271 template<>
inline bool field::to<std::string>(std::string &obj)
const 275 obj = std::string{view()};
281 inline bool field::to<std::string>(
282 std::string &obj, std::string
const &default_value)
const 288 obj = std::string{view()};
299 template<>
inline bool field::to<char const *>(
char const *&obj)
const 308 template<>
inline bool field::to<std::string_view>(std::string_view &obj)
const 318 inline bool field::to<std::string_view>(
319 std::string_view &obj, std::string_view
const &default_value)
const 330 template<>
inline std::string_view field::as<std::string_view>()
const 339 inline std::string_view
340 field::as<std::string_view>(std::string_view
const &default_value)
const 342 return is_null() ? default_value : view();
346 template<>
inline bool field::to<zview>(
zview &obj)
const 350 obj =
zview{c_str(), size()};
356 inline bool field::to<zview>(
zview &obj,
zview const &default_value)
const 362 obj =
zview{c_str(), size()};
367 template<>
inline zview field::as<zview>()
const 371 return zview{c_str(), size()};
375 template<>
inline zview field::as<zview>(
zview const &default_value)
const 377 return is_null() ? default_value :
zview{c_str(), size()};
381 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
396 virtual int sync()
override {
return traits_type::eof(); }
400 return traits_type::eof();
404 return traits_type::eof();
410 field const &m_field;
414 auto g{
static_cast<char_type *
>(
const_cast<char *
>(m_field.
c_str()))};
415 this->setg(g, g, g + std::size(m_field));
416 return int_type(std::size(m_field));
430 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
433 using super = std::basic_istream<CHAR, TRAITS>;
474 template<
typename CHAR>
475 inline std::basic_ostream<CHAR> &
476 operator<<(std::basic_ostream<CHAR> &s,
field const &value)
478 s.write(value.c_str(), std::streamsize(std::size(value)));
498 return from_string<T>(value.
view());
511 inline std::nullptr_t from_string<std::nullptr_t>(
field const &value)
513 if (not value.is_null())
515 "Extracting non-null field into nullptr_t variable."};
521 template<> PQXX_LIBEXPORT std::string
to_string(
field const &value);
524 #include "pqxx/internal/compiler-internal-post.hxx" typename traits_type::off_type off_type
Definition: field.hxx:389
Input stream that gets its data from a result field.
Definition: field.hxx:431
T as(T const &default_value) const
Return value as object of given type, or default value if null.
Definition: field.hxx:197
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:33
row_size_type m_col
Definition: field.hxx:263
CHAR char_type
Definition: field.hxx:385
field_streambuf(field const &f)
Definition: field.hxx:393
bool operator>>(T &obj) const
Read value into obj; or leave obj untouched and return false if null.
Definition: field.hxx:167
virtual int_type underflow() override
Definition: field.hxx:407
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:402
PQXX_PURE bool is_null() const noexcept
Is this field's value null?
Definition: field.cxx:66
bool composite_to(T &...fields) const
Read field as a composite value, write its components into fields.
Definition: field.hxx:153
std::ios::seekdir seekdir
Definition: field.hxx:391
auto to(T &obj) 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, leave obj untouched and return false.
Definition: field.hxx:131
field_size_type size_type
Definition: field.hxx:36
TRAITS traits_type
Definition: field.hxx:386
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:398
T from_string(field const &value)
Convert a field's value to type T.
Definition: field.hxx:487
PQXX_PURE row_size_type num() const
Definition: field.hxx:92
result const & home() const noexcept
Definition: field.hxx:255
typename traits_type::int_type int_type
Definition: field.hxx:438
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
typename traits_type::pos_type pos_type
Definition: field.hxx:388
PQXX_PURE char const * c_str() const
Read as plain C string.
Definition: field.cxx:60
typename traits_type::int_type int_type
Definition: field.hxx:387
typename traits_type::pos_type pos_type
Definition: field.hxx:439
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:499
row_size_type col() const noexcept
Definition: field.hxx:257
Traits describing a type's "null value," if any.
Definition: strconv.hxx:86
Reference to one row in a result.
Definition: row.hxx:45
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:211
basic_fieldstream(field const &f)
Definition: field.hxx:442
std::size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:30
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:24
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:331
PQXX_PURE bool operator!=(field const &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:73
Definition: field.hxx:382
PQXX_PURE std::string_view view() const
Read as string_view, or an empty one if null.
Definition: field.hxx:103
result_size_type size_type
Definition: result.hxx:73
typename traits_type::off_type off_type
Definition: field.hxx:440
CHAR char_type
Definition: field.hxx:436
virtual int sync() override
Definition: field.hxx:396
TRAITS traits_type
Definition: field.hxx:437
static TYPE null()
Return a null value.
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:242
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:181
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
std::ios::openmode openmode
Definition: field.hxx:390
array_parser as_array() const
Parse the field as an SQL array.
Definition: field.hxx:247
result::size_type idx() const noexcept
Definition: field.hxx:256
Reference to a field in a result set.
Definition: field.hxx:33
Result set containing data returned by a query or command.
Definition: result.hxx:70
Low-level array parser.
Definition: array.hxx:46
virtual int_type overflow(int_type) override
Definition: field.hxx:406