16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/compiler-internal-pre.hxx" 19 #if defined(PQXX_HAVE_OPTIONAL) 23 #if defined(PQXX_HAVE_EXP_OPTIONAL) 24 #include <experimental/optional> 27 #include "pqxx/array.hxx" 28 #include "pqxx/result.hxx" 29 #include "pqxx/strconv.hxx" 30 #include "pqxx/types.hxx" 74 bool operator==(
const field &)
const;
80 {
return !operator==(rhs);}
87 const char *name()
const;
112 const char *c_str()
const;
115 bool is_null()
const noexcept;
124 template<
typename T>
bool to(T &Obj)
const 126 const char *
const bytes = c_str();
127 if (!bytes[0] && is_null())
return false;
137 template<
typename T>
bool to(T &Obj,
const T &Default)
const 139 const bool NotNull = to(Obj);
140 if (!NotNull) Obj = Default;
148 template<
typename T> T
as(
const T &Default)
const 156 template<
typename T> T
as() const
159 const bool NotNull = to(Obj);
164 #if defined(PQXX_HAVE_OPTIONAL) 165 template<
typename T> std::optional<T>
get()
const 167 {
return get_opt<T, std::optional<T>>(); }
168 #elif defined(PQXX_HAVE_EXP_OPTIONAL) 169 template<
typename T> std::experimental::optional<T>
get()
const 171 {
return get_opt<T, std::experimental::optional<T>>(); }
187 size_t idx() const noexcept {
return m_row; }
203 template<
typename T,
typename OPTIONAL_T> OPTIONAL_T get_opt()
const 205 if (is_null())
return OPTIONAL_T();
206 else return OPTIONAL_T(as<T>());
216 inline bool field::to<std::string>(std::string &Obj)
const 218 const char *
const bytes = c_str();
219 if (!bytes[0] && is_null())
return false;
220 Obj = std::string(bytes, size());
231 inline bool field::to<const char *>(
const char *&Obj)
const 233 if (is_null())
return false;
239 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
241 public std::basic_streambuf<CHAR, TRAITS>
259 virtual int sync()
override {
return traits_type::eof(); }
263 {
return traits_type::eof(); }
265 {
return traits_type::eof();}
267 {
return traits_type::eof(); }
269 {
return traits_type::eof(); }
272 const field &m_field;
277 reinterpret_cast<char_type *
>(
const_cast<char *
>(m_field.
c_str()));
278 this->setg(G, G, G + m_field.
size());
293 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
295 public std::basic_istream<CHAR, TRAITS>
297 using super = std::basic_istream<CHAR, TRAITS>;
302 using int_type =
typename traits_type::int_type;
307 { super::init(&m_buf); }
336 template<
typename CHAR>
338 std::basic_ostream<CHAR> &S,
const field &F)
340 S.write(F.
c_str(), std::streamsize(F.
size()));
351 template<> PQXX_LIBEXPORT std::string
to_string(
const field &Obj);
354 #include "pqxx/compiler-internal-post.hxx" typename traits_type::off_type off_type
Definition: field.hxx:248
size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:28
virtual int_type overflow(int_type) override
Definition: field.hxx:266
row_size_type num() const
Definition: field.hxx:96
Reference to one row in a result.
Definition: row.hxx:40
bool operator!=(const field &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:79
Input stream that gets its data from a result field.
Definition: field.hxx:294
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
CHAR char_type
Definition: field.hxx:244
bool to(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:124
virtual int sync() override
Definition: field.hxx:259
Definition: field.hxx:240
virtual int_type underflow() override
Definition: field.hxx:268
Low-level array parser.
Definition: array.hxx:38
TRAITS traits_type
Definition: field.hxx:245
array_parser as_array() const
Parse the field as an SQL array.
Definition: field.hxx:181
basic_fieldstream(const field &F)
Definition: field.hxx:306
Result set containing data returned by a query or command.
Definition: result.hxx:67
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:156
size_t idx() const noexcept
Definition: field.hxx:187
const result & home() const noexcept
Definition: field.hxx:186
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:347
bool to(T &Obj, const T &Default) const
Read value into Obj; or use Default & return false if null.
Definition: field.hxx:137
TRAITS traits_type
Definition: field.hxx:301
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:337
virtual pos_type seekoff(off_type, seekdir, openmode) override
Definition: field.hxx:262
field_size_type size_type
Definition: field.hxx:44
unsigned int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:22
field_streambuf(const field &F)
Definition: field.hxx:252
row_size_type col() const noexcept
Definition: field.hxx:188
typename traits_type::pos_type pos_type
Definition: field.hxx:303
typename traits_type::int_type int_type
Definition: field.hxx:246
std::ios::openmode openmode
Definition: field.hxx:249
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
const char * c_str() const
Read as plain C string.
Definition: field.cxx:62
long m_col
Definition: field.hxx:194
std::ios::seekdir seekdir
Definition: field.hxx:250
bool operator>>(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:133
CHAR char_type
Definition: field.hxx:300
virtual pos_type seekpos(pos_type, openmode) override
Definition: field.hxx:264
typename traits_type::off_type off_type
Definition: field.hxx:304
Reference to a field in a result set.
Definition: field.hxx:41
Traits class for use in string conversions.
Definition: strconv.hxx:39
typename traits_type::pos_type pos_type
Definition: field.hxx:247
T as(const T &Default) const
Return value as object of given type, or Default if null.
Definition: field.hxx:148
size_type size() const noexcept
Return number of bytes taken up by the field's value.
Definition: field.cxx:74