16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
75 [[nodiscard]]
PQXX_PURE char const *name() const &;
113 return std::string_view(c_str(), size());
126 [[nodiscard]]
PQXX_PURE char const *c_str() const &;
132 [[nodiscard]]
PQXX_PURE size_type size() const noexcept;
139 auto to(T &obj) const ->
140 typename std::enable_if_t<
141 (not std::is_pointer<T>::value or std::is_same<T,
char const *>::value),
150 auto const data{c_str()};
176 template<
typename T>
bool operator>>(T &obj)
const {
return to(obj); }
190 auto to(T &obj, T
const &default_value)
const ->
191 typename std::enable_if_t<
192 (not std::is_pointer<T>::value or std::is_same<T, char const *>::value),
199 obj = from_string<T>(this->view());
207 template<
typename T> T
as(T
const &default_value)
const
210 return default_value;
212 return from_string<T>(this->view());
221 template<
typename T> T
as()
const
232 return from_string<T>(this->view());
240 template<
typename T,
template<
typename>
class O = std::optional>
241 constexpr O<T>
get()
const
247 template<
typename ELEMENT,
auto... ARGS>
250 using array_type =
array<ELEMENT, ARGS...>;
256 return array_type{this->view(), this->m_home.m_encoding};
267 "Avoid pqxx::array_parser. "
268 "Instead, use as_sql_array() to convert to pqxx::array.")]]
281 "Do not construct fields yourself. Get them from the row.")]]
field(
row const &r,
row_size_type c) noexcept;
285 "Do not construct fields yourself. Get them from the "
286 "row.")]]
field() noexcept = default;
290 constexpr
result const &home() const noexcept {
return m_home; }
300 m_col{col_num}, m_home{r}, m_row{row_num}
315 template<>
inline bool field::to<std::string>(std::string &obj)
const
319 obj = std::string{view()};
325 inline bool field::to<std::string>(
326 std::string &obj, std::string
const &default_value)
const
332 obj = std::string{view()};
343 template<>
inline bool field::to<char const *>(
char const *&obj)
const
352 template<>
inline bool field::to<std::string_view>(std::string_view &obj)
const
362 inline bool field::to<std::string_view>(
363 std::string_view &obj, std::string_view
const &default_value)
const
374 template<>
inline std::string_view field::as<std::string_view>()
const
384 inline std::string_view
385 field::as<std::string_view>(std::string_view
const &default_value)
const
387 return is_null() ? default_value : view();
391 template<>
inline bool field::to<zview>(
zview &obj)
const
401 inline bool field::to<zview>(
zview &obj,
zview const &default_value)
const
412 template<>
inline zview field::as<zview>()
const
421 template<>
inline zview field::as<zview>(
zview const &default_value)
const
427 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
442 virtual int sync()
override {
return traits_type::eof(); }
446 return traits_type::eof();
450 return traits_type::eof();
456 field const &m_field;
460 auto g{
static_cast<char_type *
>(
const_cast<char *
>(m_field.
c_str()))};
461 this->setg(g, g, g + std::size(m_field));
462 return int_type(std::size(m_field));
481 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
484 using super = std::basic_istream<CHAR, TRAITS>;
495 super{
nullptr}, m_buf{f}
501 field_streambuf<CHAR, TRAITS> m_buf;
533 template<
typename CHAR>
535 "Do this by hand, probably with better error checking.")]]
inline std::
536 basic_ostream<CHAR> &
537 operator<<(std::basic_ostream<CHAR> &s,
field const &value)
539 s.write(value.c_str(), std::streamsize(std::size(value)));
559 return from_string<T>(value.
view());
572 inline std::nullptr_t from_string<std::nullptr_t>(
field const &value)
574 if (not value.is_null())
576 "Extracting non-null field into nullptr_t variable."};
virtual int_type underflow() override
Definition: field.hxx:453
constexpr row_size_type col() const noexcept
Definition: field.hxx:292
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
bool operator>>(T &obj) const
Read value into obj; or leave obj untouched and return false if null.
Definition: field.hxx:176
std::ios::seekdir seekdir
Definition: field.hxx:437
virtual int_type overflow(int_type) override
Definition: field.hxx:452
constexpr size_type size() const noexcept
Definition: row.hxx:106
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:448
Definition: field.hxx:428
bool operator==(stream_query_end_iterator, stream_query_input_iterator< TYPE... > const &i)
Definition: stream_query_impl.hxx:135
Low-level parser for C++ arrays.
Definition: array.hxx:530
field_size_type size_type
Definition: field.hxx:37
Reference to one row in a result.
Definition: row.hxx:46
T from_string(field const &value)
Convert a field's value to type T.
Definition: field.hxx:548
typename traits_type::off_type off_type
Definition: field.hxx:435
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:46
Result set containing data returned by a query or command.
Definition: result.hxx:91
PQXX_LIBEXPORT std::string to_string(field const &value)
Convert a field to a string.
array_parser as_array() const &noexcept
Parse the field as an SQL array.
Definition: field.hxx:269
bool composite_to(T &...fields) const
Read field as a composite value, write its components into fields.
Definition: field.hxx:162
typename traits_type::off_type off_type
Definition: field.hxx:491
int result_size_type
Number of rows in a result set.
Definition: types.hxx:40
array< ELEMENT, ARGS... > as_sql_array() const
Read SQL array contents as a pqxx::array.
Definition: field.hxx:248
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:499
PQXX_PURE std::string_view view() const &
Read as string_view, or an empty one if null.
Definition: field.hxx:111
basic_fieldstream(field const &f)
Definition: field.hxx:493
T as(T const &default_value) const
Return value as object of given type, or default value if null.
Definition: field.hxx:207
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:190
typename traits_type::int_type int_type
Definition: field.hxx:433
typename traits_type::pos_type pos_type
Definition: field.hxx:490
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:282
constexpr result::size_type idx() const noexcept
Definition: field.hxx:291
virtual int sync() override
Definition: field.hxx:442
static TYPE null()
Return a null value.
field_streambuf(field const &f)
Definition: field.hxx:439
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
Reference to a field in a result set.
Definition: field.hxx:34
std::ios::openmode openmode
Definition: field.hxx:436
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:444
PQXX_PURE constexpr std::string_view name_type< zview >() noexcept
Definition: zview.hxx:118
unsigned int oid
PostgreSQL database row identifier.
Definition: libpq-forward.hxx:33
CHAR char_type
Definition: field.hxx:431
TRAITS traits_type
Definition: field.hxx:432
result_size_type size_type
Definition: result.hxx:94
std::size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:52
Traits describing a type's "null value," if any.
Definition: strconv.hxx:69
void throw_null_conversion(std::string const &type)
Throw exception for attempt to convert SQL NULL to given type.
Definition: strconv.cxx:257
row_size_type m_col
Definition: field.hxx:307
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
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:221
typename traits_type::pos_type pos_type
Definition: field.hxx:434
Input stream that gets its data from a result field.
Definition: field.hxx:482
field(result const &r, result_size_type row_num, row_size_type col_num) noexcept
Definition: field.hxx:297
PQXX_PURE char const * c_str() const &
Read as plain C string.
Definition: field.cxx:65
typename traits_type::int_type int_type
Definition: field.hxx:489
PQXX_PURE bool is_null() const noexcept
Is this field's value null?
Definition: field.cxx:71
An SQL array received from the database.
Definition: array.hxx:55
CHAR char_type
Definition: field.hxx:487
TRAITS traits_type
Definition: field.hxx:488