16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 21 #include "pqxx/array.hxx" 22 #include "pqxx/result.hxx" 23 #include "pqxx/strconv.hxx" 24 #include "pqxx/types.hxx" 65 [[nodiscard]]
bool operator==(
field const &)
const;
72 return not operator==(rhs);
80 [[nodiscard]]
char const *name()
const;
84 [[nodiscard]] oid type()
const;
87 [[nodiscard]] oid table()
const;
99 [[nodiscard]] std::string_view view()
const 102 return std::string_view(c_str(), size());
111 [[nodiscard]]
char const *c_str()
const;
114 [[nodiscard]]
bool is_null() const noexcept;
120 [[nodiscard]] size_type size() const noexcept;
127 auto to(T &obj) const -> typename std::enable_if<
128 (not std::is_pointer<T>::value or std::is_same<T,
char const *>::value),
131 auto const bytes{c_str()};
132 if (bytes[0] ==
'\0' and
is_null())
139 template<
typename T>
bool operator>>(T &obj)
const {
return to(obj); }
146 auto to(T &obj, T
const &default_value)
const ->
typename std::enable_if<
147 (not std::is_pointer<T>::value or std::is_same<T, char const *>::value),
150 bool const has_value{to(obj)};
160 template<
typename T> T
as(T
const &default_value)
const 163 to(obj, default_value);
173 template<
typename T> T
as()
const 178 if constexpr (nullness<T>::has_null)
179 obj = nullness<T>::null();
181 internal::throw_null_conversion(type_name<T>);
190 template<
typename T,
template<
typename>
class O = std::optional>
191 constexpr O<T>
get()
const 211 result
const &
home() const noexcept {
return m_home; }
212 result::size_type
idx() const noexcept {
return m_row; }
223 result::size_type m_row;
228 template<>
inline bool field::to<std::string>(std::string &obj)
const 230 char const *
const bytes = c_str();
231 if (bytes[0] ==
'\0' and
is_null())
233 obj = std::string{bytes, size()};
243 template<>
inline bool field::to<char const *>(
char const *&obj)
const 252 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
267 virtual int sync()
override {
return traits_type::eof(); }
271 return traits_type::eof();
275 return traits_type::eof();
281 field const &m_field;
285 auto g{static_cast<char_type *>(const_cast<char *>(m_field.
c_str()))};
286 this->setg(g, g, g + m_field.
size());
301 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
304 using super = std::basic_istream<CHAR, TRAITS>;
319 field_streambuf<CHAR, TRAITS> m_buf;
345 template<
typename CHAR>
346 inline std::basic_ostream<CHAR> &
349 s.write(value.
c_str(), std::streamsize(value.
size()));
357 return from_string<T>(value.
view());
361 template<> PQXX_LIBEXPORT std::string
to_string(field
const &value);
364 #include "pqxx/internal/compiler-internal-post.hxx" virtual int sync() override
Definition: field.hxx:267
bool operator!=(field const &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:70
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:273
bool is_null(TYPE const &value)
Is value null?
Definition: strconv.hxx:286
typename traits_type::int_type int_type
Definition: field.hxx:258
virtual int_type overflow(int_type) override
Definition: field.hxx:277
typename traits_type::pos_type pos_type
Definition: field.hxx:259
row_size_type num() const
Definition: field.hxx:89
char const * c_str() const
Read as plain C string.
Definition: field.cxx:62
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:173
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:478
T from_string(field const &value)
Convert a field's string contents to another type.
Definition: field.hxx:355
auto to(T &obj, T const &default_value) const -> typename std::enable_if<(not std::is_pointer< T >::value or std::is_same< T, char const * >::value), bool >::type
Read value into obj; or if null, use default value and return false.
Definition: field.hxx:146
Reference to a field in a result set.
Definition: field.hxx:32
result const & home() const noexcept
Definition: field.hxx:211
result::size_type idx() const noexcept
Definition: field.hxx:212
Input stream that gets its data from a result field.
Definition: field.hxx:302
TRAITS traits_type
Definition: field.hxx:257
std::ios::seekdir seekdir
Definition: field.hxx:262
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:269
size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:30
std::ios::openmode openmode
Definition: field.hxx:261
row_size_type m_col
Definition: field.hxx:219
std::string_view view() const
Read as string_view.
Definition: field.hxx:100
TRAITS traits_type
Definition: field.hxx:308
bool operator>>(T &obj) const
Read value into obj; or leave obj untouched and return false if null.
Definition: field.hxx:139
size_type size() const noexcept
Return number of bytes taken up by the field's value.
Definition: field.cxx:74
row_size_type col() const noexcept
Definition: field.hxx:213
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:24
field_streambuf(field const &f)
Definition: field.hxx:264
Low-level array parser.
Definition: array.hxx:46
Definition: field.hxx:253
T as(T const &default_value) const
Return value as object of given type, or default value if null.
Definition: field.hxx:160
CHAR char_type
Definition: field.hxx:307
Reference to one row in a result.
Definition: row.hxx:38
Dedicated namespace for helper types related to prepared statements.
Definition: array.hxx:25
typename traits_type::pos_type pos_type
Definition: field.hxx:310
CHAR char_type
Definition: field.hxx:256
bool is_null() const noexcept
Is this field's value null?
Definition: field.cxx:68
constexpr O< T > get() const
Return value wrapped in some optional type (empty for nulls).
Definition: field.hxx:191
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:347
field_size_type size_type
Definition: field.hxx:35
basic_fieldstream(field const &f)
Definition: field.hxx:313
virtual int_type underflow() override
Definition: field.hxx:278
array_parser as_array() const
Parse the field as an SQL array.
Definition: field.hxx:203
typename traits_type::off_type off_type
Definition: field.hxx:260
typename traits_type::off_type off_type
Definition: field.hxx:311
typename traits_type::int_type int_type
Definition: field.hxx:309