Reference to a field in a result set. More...
#include <field.hxx>
Public Types | |
typedef size_t | size_type |
Public Member Functions | |
field (const row &R, row_size_type C) PQXX_NOEXCEPT | |
Constructor. | |
template<> | |
bool | to (const char *&Obj) const |
Specialization: to(const char *&) . | |
Comparison | |
bool | operator== (const field &) const |
Byte-by-byte comparison of two fields (all nulls are considered equal). | |
bool | operator!= (const field &rhs) const |
Byte-by-byte comparison (all nulls are considered equal). | |
Column information | |
const char * | name () const |
Column name. | |
oid | type () const |
Column type. | |
oid | table () const |
What table did this column come from? | |
row_size_type | num () const |
row_size_type | table_column () const |
What column number in its originating table did this column come from? | |
Content access | |
const char * | c_str () const |
Read as plain C string. | |
template<typename T > | |
bool | to (T &Obj) const |
Read value into Obj; or leave Obj untouched and return false if null. | |
template<typename T > | |
bool | operator>> (T &Obj) const |
Read value into Obj; or leave Obj untouched and return false if null. | |
template<typename T > | |
bool | to (T &Obj, const T &Default) const |
Read value into Obj; or use Default & return false if null. | |
template<typename T > | |
T | as (const T &Default) const |
Return value as object of given type, or Default if null. | |
template<typename T > | |
T | as () const |
Return value as object of given type, or throw exception if null. | |
bool | is_null () const PQXX_NOEXCEPT |
Is this field's value null? | |
size_type | size () const PQXX_NOEXCEPT |
Return number of bytes taken up by the field's value. | |
Protected Member Functions | |
const result * | home () const PQXX_NOEXCEPT |
size_t | idx () const PQXX_NOEXCEPT |
row_size_type | col () const PQXX_NOEXCEPT |
Protected Attributes | |
row_size_type | m_col |
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.
typedef size_t pqxx::field::size_type |
Reimplemented in pqxx::const_row_iterator.
pqxx::field::field | ( | const row & | R, | |
row_size_type | C | |||
) |
T pqxx::field::as | ( | ) | const |
Return value as object of given type, or throw exception if null.
T pqxx::field::as | ( | const T & | Default | ) | const |
Return value as object of given type, or Default if null.
Note that unless the function is instantiated with an explicit template argument, the Default value's type also determines the result type.
const char * pqxx::field::c_str | ( | ) | const |
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 to() or as() functions to convert the string to other types such as int
, or to C++ strings.
References col(), home(), and idx().
Referenced by pqxx::binarystring::binarystring(), pqxx::from_string(), pqxx::operator<<(), operator==(), and pqxx::to_string().
row_size_type pqxx::field::col | ( | ) | const [protected] |
Referenced by c_str(), is_null(), name(), pqxx::const_row_iterator::operator+(), pqxx::const_row_iterator::operator-(), size(), table(), table_column(), and type().
const result* pqxx::field::home | ( | ) | const [protected] |
Referenced by c_str(), is_null(), name(), pqxx::const_row_iterator::operator+(), pqxx::const_row_iterator::operator-(), size(), table(), table_column(), and type().
size_t pqxx::field::idx | ( | ) | const [protected] |
Referenced by c_str(), is_null(), pqxx::const_row_iterator::operator+(), pqxx::const_row_iterator::operator-(), and size().
bool pqxx::field::is_null | ( | ) | const |
const char * pqxx::field::name | ( | ) | const |
Column name.
References col(), pqxx::result::column_name(), and home().
row_size_type pqxx::field::num | ( | ) | const |
Referenced by pqxx::const_row_iterator::operator-().
bool pqxx::field::operator!= | ( | const field & | rhs | ) | const |
Byte-by-byte comparison (all nulls are considered equal).
Reimplemented in pqxx::const_row_iterator, and pqxx::const_reverse_row_iterator.
bool pqxx::field::operator== | ( | const field & | rhs | ) | const |
Byte-by-byte comparison of two fields (all nulls are considered equal).
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.
Reimplemented in pqxx::const_row_iterator, and pqxx::const_reverse_row_iterator.
bool pqxx::field::operator>> | ( | T & | Obj | ) | const |
Read value into Obj; or leave Obj untouched and return false
if null.
pqxx::field::size_type pqxx::field::size | ( | ) | const |
Return number of bytes taken up by the field's value.
Includes the terminating zero byte.
References col(), home(), and idx().
Referenced by pqxx::from_string(), pqxx::operator<<(), operator==(), and pqxx::to_string().
pqxx::oid pqxx::field::table | ( | ) | const |
What table did this column come from?
References col(), pqxx::result::column_table(), and home().
pqxx::row::size_type pqxx::field::table_column | ( | ) | const |
What column number in its originating table did this column come from?
References col(), home(), and pqxx::result::table_column().
bool pqxx::field::to | ( | const char *& | Obj | ) | const |
bool pqxx::field::to | ( | T & | Obj, | |
const T & | Default | |||
) | const |
Read value into Obj; or use Default & return false
if null.
bool pqxx::field::to | ( | T & | Obj | ) | const |
Read value into Obj; or leave Obj untouched and return false
if null.
References pqxx::from_string().
pqxx::oid pqxx::field::type | ( | ) | const |
Column type.
References col(), pqxx::result::column_type(), and home().
row_size_type pqxx::field::m_col [protected] |
Referenced by pqxx::const_row_iterator::operator++(), and pqxx::const_row_iterator::operator--().