16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/compiler-internal-pre.hxx" 19 #if defined(PQXX_HAVE_OPTIONAL) 31 #if defined(PQXX_HAVE_EXP_OPTIONAL) && !defined(PQXX_HIDE_EXP_OPTIONAL) 32 #include <experimental/optional> 35 #include "pqxx/array.hxx" 36 #include "pqxx/result.hxx" 37 #include "pqxx/strconv.hxx" 38 #include "pqxx/types.hxx" 82 bool operator==(
const field &)
const;
88 {
return !operator==(rhs);}
95 const char *name()
const;
120 const char *c_str()
const;
123 bool is_null()
const noexcept;
132 template<
typename T>
bool to(T &Obj)
const 134 const char *
const bytes = c_str();
135 if (!bytes[0] && is_null())
return false;
145 template<
typename T>
bool to(T &Obj,
const T &Default)
const 147 const bool NotNull = to(Obj);
148 if (!NotNull) Obj = Default;
156 template<
typename T> T
as(
const T &Default)
const 164 template<
typename T> T
as() const
167 const bool NotNull = to(Obj);
172 #if defined(PQXX_HAVE_OPTIONAL) 173 template<
typename T> std::optional<T>
get()
const 175 {
return get_opt<T, std::optional<T>>(); }
176 #elif defined(PQXX_HAVE_EXP_OPTIONAL) && !defined(PQXX_HIDE_EXP_OPTIONAL) 177 template<
typename T> std::experimental::optional<T>
get()
const 179 {
return get_opt<T, std::experimental::optional<T>>(); }
195 size_t idx() const noexcept {
return m_row; }
211 template<
typename T,
typename OPTIONAL_T> OPTIONAL_T get_opt()
const 213 if (is_null())
return OPTIONAL_T();
214 else return OPTIONAL_T(as<T>());
224 inline bool field::to<std::string>(std::string &Obj)
const 226 const char *
const bytes = c_str();
227 if (!bytes[0] && is_null())
return false;
228 Obj = std::string(bytes, size());
239 inline bool field::to<const char *>(
const char *&Obj)
const 241 if (is_null())
return false;
247 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
249 public std::basic_streambuf<CHAR, TRAITS>
267 virtual int sync()
override {
return traits_type::eof(); }
271 {
return traits_type::eof(); }
273 {
return traits_type::eof();}
275 {
return traits_type::eof(); }
277 {
return traits_type::eof(); }
280 const field &m_field;
285 reinterpret_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>>
303 public std::basic_istream<CHAR, TRAITS>
305 using super = std::basic_istream<CHAR, TRAITS>;
310 using int_type =
typename traits_type::int_type;
315 { super::init(&m_buf); }
344 template<
typename CHAR>
346 std::basic_ostream<CHAR> &S,
const field &F)
348 S.write(F.
c_str(), std::streamsize(F.
size()));
359 template<> PQXX_LIBEXPORT std::string
to_string(
const field &Obj);
362 #include "pqxx/compiler-internal-post.hxx" TRAITS traits_type
Definition: field.hxx:253
size_t idx() const noexcept
Definition: field.hxx:195
bool to(T &Obj, const T &Default) const
Read value into Obj; or use Default & return false if null.
Definition: field.hxx:145
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:164
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:260
row_size_type col() const noexcept
Definition: field.hxx:196
typename traits_type::int_type int_type
Definition: field.hxx:254
CHAR char_type
Definition: field.hxx:308
const result & home() const noexcept
Definition: field.hxx:194
std::ios::openmode openmode
Definition: field.hxx:257
TRAITS traits_type
Definition: field.hxx:309
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:355
typename traits_type::off_type off_type
Definition: field.hxx:312
std::ios::seekdir seekdir
Definition: field.hxx:258
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:345
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:270
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:302
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:272
const char * c_str() const
Read as plain C string.
Definition: field.cxx:62
field_size_type size_type
Definition: field.hxx:52
row_size_type num() const
Definition: field.hxx:104
T as(const T &Default) const
Return value as object of given type, or Default if null.
Definition: field.hxx:156
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
basic_fieldstream(const field &F)
Definition: field.hxx:314
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:255
long m_col
Definition: field.hxx:202
Definition: field.hxx:248
bool operator>>(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:141
bool operator!=(const field &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:87
typename traits_type::off_type off_type
Definition: field.hxx:256
Reference to a field in a result set.
Definition: field.hxx:49
virtual int_type overflow(int_type) override
Definition: field.hxx:274
Traits class for use in string conversions.
Definition: strconv.hxx:39
typename traits_type::pos_type pos_type
Definition: field.hxx:311
bool to(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:132
virtual int_type underflow() override
Definition: field.hxx:276
CHAR char_type
Definition: field.hxx:252
virtual int sync() override
Definition: field.hxx:267
Low-level array parser.
Definition: array.hxx:38
array_parser as_array() const
Parse the field as an SQL array.
Definition: field.hxx:189