|
| | field (row const &r, row_size_type c) noexcept |
| | Constructor. Do not call this yourself; libpqxx will do it for you. More...
|
| |
| | field () noexcept=default |
| | Constructor. Do not call this yourself; libpqxx will do it for you. More...
|
| |
| template<> |
| bool | to (char const *&obj) const |
| | Specialization: to(char const *&). More...
|
| |
| template<> |
| bool | to (zview &obj) const |
| |
| template<> |
| bool | to (zview &obj, zview const &default_value) const |
| |
| template<> |
| zview | as () const |
| |
| template<> |
| zview | as (zview const &default_value) const |
| |
|
| PQXX_PURE bool | operator== (field const &) const noexcept |
| | Byte-by-byte comparison of two fields (all nulls are considered equal) More...
|
| |
| PQXX_PURE bool | operator!= (field const &rhs) const noexcept |
| | Byte-by-byte comparison (all nulls are considered equal) More...
|
| |
|
| PQXX_PURE char const * | name () const & |
| | Column name. More...
|
| |
| oid PQXX_PURE | type () const |
| | Column type. More...
|
| |
| PQXX_PURE oid | table () const |
| | What table did this column come from? More...
|
| |
| PQXX_PURE constexpr row_size_type | num () const noexcept |
| | Return column number. The first column is 0, the second is 1, etc. More...
|
| |
| PQXX_PURE row_size_type | table_column () const |
| | What column number in its originating table did this column come from? More...
|
| |
|
You can read a field as any C++ type for which a conversion from PostgreSQL's text format is defined. See Supporting additional data types for how this works. This mechanism is weakly typed: the conversions do not care what SQL type a field had in the database, only that its actual contents convert to the target type without problems. So for instance, you can read a text field as an int, so long as the string in the field spells out a valid int number.
Many built-in types come with conversions predefined. To find out how to add your own, see Supporting additional data types.
|
| PQXX_PURE std::string_view | view () const & |
| | Read as string_view, or an empty one if null. More...
|
| |
| PQXX_PURE char const * | c_str () const & |
| | Read as plain C string. More...
|
| |
| PQXX_PURE bool | is_null () const noexcept |
| | Is this field's value null? More...
|
| |
| PQXX_PURE size_type | size () const noexcept |
| | Return number of bytes taken up by the field's value. More...
|
| |
| template<typename T > |
| 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. More...
|
| |
| template<typename... T> |
| bool | composite_to (T &...fields) const |
| | Read field as a composite value, write its components into fields. More...
|
| |
| template<typename T > |
| bool | operator>> (T &obj) const |
| | Read value into obj; or leave obj untouched and return false if null. More...
|
| |
| template<typename T > |
| 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. More...
|
| |
| template<typename T > |
| T | as (T const &default_value) const |
| | Return value as object of given type, or default value if null. More...
|
| |
| template<typename T > |
| T | as () const |
| | Return value as object of given type, or throw exception if null. More...
|
| |
| template<typename T , template< typename > class O = std::optional> |
| constexpr O< T > | get () const |
| | Return value wrapped in some optional type (empty for nulls). More...
|
| |
| template<typename ELEMENT , auto... ARGS> |
| array< ELEMENT, ARGS... > | as_sql_array () const |
| | Read SQL array contents as a pqxx::array. More...
|
| |
| array_parser | as_array () const &noexcept |
| | Parse the field as an SQL array. More...
|
| |
Reference to a field in a result set.
A field represents one entry in a row. It represents an actual value in the result set, and can be converted to various types.
Constructor. Do not call this yourself; libpqxx will do it for you.
Create field as reference to a field in a result set.
- Parameters
-
| r | Row that this field is part of. |
| c | Column number of this field. |
Implementation of the pqxx::field class.
pqxx::field refers to a field in a query result.
Copyright (c) 2000-2025, Jeroen T. Vermeulen.
See COPYING for copyright license. If you did not receive a file called COPYING with this source code, please notify the distributor of this mistake, or contact the author.
| bool pqxx::field::operator== |
( |
field const & |
rhs | ) |
const |
|
noexcept |
Byte-by-byte comparison of two fields (all nulls are considered equal)
- Warning
- null handling is still open to discussion and change!
Handling of null values differs from that in SQL where a comparison involving a null value yields null, so nulls are never considered equal to one another or even to themselves.
Null handling also probably differs from the closest equivalent in C++, which is the NaN (Not-a-Number) value, a singularity comparable to SQL's null. This is because the builtin == operator demands that a == a.
The usefulness of this operator is questionable. No interpretation whatsoever is imposed on the data; 0 and 0.0 are considered different, as are null vs. the empty string, or even different (but possibly equivalent and equally valid) encodings of the same Unicode character etc.
template<typename T >
| auto pqxx::field::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>
|
|
inline |
Read value into obj; or if null, use default value and return false.
This can be used with std::optional, as well as with standard smart pointer types, but not with raw pointers. If the conversion from a PostgreSQL string representation allocates a pointer (e.g. using new), then the object's later deallocation should be baked in as well, right from the point where the object is created. So if you want a pointer, use a smart pointer, not a raw pointer.
There is one exception, of course: C-style strings. Those are just pointers to the field's internal text data.