|
libpqxx
The C++ client library for PostgreSQL
|
Lightweight reference to a field in a result set. More...
#include <field.hxx>
Public Types | |
| using | size_type = field_size_type |
| A type for holding the number of bytes in a field. More... | |
Public Member Functions | |
| field_ref () noexcept=default | |
| field_ref (field_ref const &) noexcept=default | |
| field_ref (field_ref &&) noexcept=default | |
| field_ref (result const &res, result_size_type row_num, row_size_type col_num) noexcept | |
| ~field_ref ()=default | |
| field_ref & | operator= (field_ref const &) noexcept=default |
| field_ref & | operator= (field_ref &&) noexcept=default |
| PQXX_PURE result const & | home () const noexcept |
| PQXX_PURE result_size_type | row_number () const noexcept |
| template<> | |
| zview | as (sl loc) const |
Efficient specialisation: you can convert a field to a zview. More... | |
Comparison | |
Equality between two So, if you copy a result, even though the two copies refer to the exact same underlying data structure, a | |
| PQXX_PURE bool | operator== (field_ref const &rhs) const noexcept |
| PQXX_PURE bool | operator!= (field_ref const &rhs) const noexcept |
Column information | |
| PQXX_PURE char const * | name (sl loc=sl::current()) const & |
| Column name. More... | |
| PQXX_PURE oid | type (sl loc=sl::current()) const |
| Column type. More... | |
| PQXX_PURE oid | table (sl=sl::current()) const |
| What table did this column come from? More... | |
| constexpr PQXX_PURE row_size_type | column_number () const noexcept |
| Return column number. The first column is 0, the second is 1, etc. More... | |
| PQXX_PURE row_size_type | table_column (sl loc=sl::current()) const |
| What column number in its originating table did this column come from? More... | |
Content access | |
You can read a Many built-in types come with conversions predefined. To find out how to add your own, see Supporting additional data types. | |
| class | pqxx::internal::gate::field_ref_const_row_iterator |
| PQXX_PURE std::string_view | view () const &noexcept |
| Read as zview, or an empty one if null. More... | |
| PQXX_PURE char const * | c_str () const &noexcept |
| 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 > | |
| T | as (T const &default_value, sl loc=sl::current()) const |
Return value as object of given type, or default value if null. More... | |
| template<typename T > | |
| T | as (sl loc=sl::current()) const |
| Return value as object of given type, or throw exception if null. More... | |
| template<typename T > | |
| bool | to (T &obj, sl loc=sl::current()) const |
Read value into obj; or if null, leave obj untouched. More... | |
| template<typename T > | |
| bool | to (T &obj, T const &default_value, sl loc=sl::current()) const |
Read value into obj; or if null, set default value and return false. More... | |
| template<typename T , template< typename > typename 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 (sl loc=sl::current()) const |
| Read SQL array contents as a pqxx::array. More... | |
Lightweight reference to a field in a result set.
Like field, represents one field in a query result set. Unlike with field, however, for as long as you're using a field_ref, the result object must...
When you use field_ref, it is your responsibility to ensure all that.
You can query whether a field_ref is null, and if not, you can convert its value from its textual "SQL representation" to a more suitable C++ type.
A type for holding the number of bytes in a field.
|
defaultnoexcept |
|
defaultnoexcept |
|
defaultnoexcept |
|
inlinenoexcept |
|
default |
Efficient specialisation: you can convert a field to a zview.
String conversions generally accept std::string_view. You can't just "convert" any old std::string_view to a pqxx::zview because zview is a promise that the string is zero-terminated. One can't generally make that promise based on a string_view.
|
inline |
Return value as object of given type, or throw exception if null.
Use as as<std::optional<int>>() or as<my_untemplated_optional_t>() as an alternative to get<int>(); this is disabled for use with raw pointers (other than C-strings) because storage for the value can't safely be allocated here
|
inline |
Return value as object of given type, or default value if null.
Note that unless the function is instantiated with an explicit template argument, the Default value's type also determines the result type.
|
inline |
Read SQL array contents as a pqxx::array.
|
inlinenoexcept |
Read as plain C string.
Since the field's data is stored internally in the form of a zero-terminated C string, this is the fastest way to read it. Use the is_null() and as() functions to convert the string to other types such as int, or to C++ strings.
c_str() for those. Instead, convert the value to a binary type using as(), e.g. f.as<pqxx::bytes>().
|
inlineconstexprnoexcept |
Return column number. The first column is 0, the second is 1, etc.
|
inlineconstexpr |
Return value wrapped in some optional type (empty for nulls).
Use as get<int>() as before to obtain previous behavior, or specify container type with get<int, std::optional>()
|
inlinenoexcept |
Is this field's value null?
|
inlinenoexcept |
|
inlinenoexcept |
Return number of bytes taken up by the field's value.
What table did this column come from?
|
inline |
What column number in its originating table did this column come from?
|
inline |
Read value into obj; or if null, leave obj untouched.
This can be handy to read a field's value but also check for nullness along the way.
true for a non-null field, or false for a null field.
|
inline |
Read value into obj; or if null, set default value and return false.
|
inlinenoexcept |
|
friend |