Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pqxx::result::field Class Reference

Reference to a field in a result set. More...

#include <result.hxx>

Inheritance diagram for pqxx::result::field:

pqxx::result::tuple List of all members.

Public Types

typedef size_t size_type

Public Member Functions

 field (const tuple &R, tuple::size_type C) throw ()
 Constructor.

const char * c_str () const
 Read as plain C string.

const char * name () const
 Column name.

oid type () const
 Column type.

template<typename T> bool to (T &Obj) const
 Read value into Obj; or leave Obj untouched & 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
size_type size () const

Detailed Description

Reference to a field in a result set.

A field represents one entry in a tuple. It represents an actual value in the result set, and can be converted to various types.


Member Typedef Documentation

typedef size_t pqxx::result::field::size_type
 

Reimplemented from pqxx::result::tuple.


Constructor & Destructor Documentation

pqxx::result::field::field const tuple R,
tuple::size_type  C
throw ()
 

Constructor.

Create field as reference to a field in a result set.

Parameters:
R tuple that this field is part of.
C column number of this field.


Member Function Documentation

template<typename T>
T pqxx::result::field::as  )  const
 

Return value as object of given type, or throw exception if null.

template<typename T>
T pqxx::result::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::result::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.

bool pqxx::result::field::is_null  )  const
 

const char * pqxx::result::field::name  )  const
 

Column name.

size_type pqxx::result::field::size  )  const
 

Reimplemented from pqxx::result::tuple.

template<typename T>
bool pqxx::result::field::to T &  Obj,
const T &  Default
const
 

Read value into Obj; or use Default & return false if null.

template<typename T>
bool pqxx::result::field::to T &  Obj  )  const
 

Read value into Obj; or leave Obj untouched & return false if null.

Warning:
The conversion is done using the currently active locale, whereas PostgreSQL delivers values in the "default" (C) locale. This means that if you intend to use this function from a locale that doesn't understand the data types in question (particularly numeric types like float and int) in default C format, you'll need to switch back to the C locale before the call--at least insofar as numeric formatting is concerned (on POSIX systems, use setlocale(LC_NUMERIC, "C")). This should be fixed at some point in the future.

oid pqxx::result::field::type  )  const
 

Column type.


The documentation for this class was generated from the following file:
Generated on Thu Jun 17 18:47:10 2004 for libpqxx by doxygen 1.3.7