libpqxx  v4.0-1
C++ library for PostgreSQL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
String conversion

For purposes of communication with the server, values need to be converted from and to a human-readable string format that (unlike the various functions and templates in the C and C++ standard libraries) is not sensitive to locale settings and internationalization. More...

Namespaces

namespace  pqxx::internal
 Private namespace for libpqxx's internal use; do not access.
 

Classes

struct  pqxx::string_traits< T >
 Traits class for use in string conversions. More...
 
struct  pqxx::string_traits< bool >
 
struct  pqxx::string_traits< char * >
 String traits for non-const C-style string ("pointer to char") More...
 
struct  pqxx::string_traits< char[N]>
 String traits for C-style string constant ("array of char") More...
 
struct  pqxx::string_traits< const char * >
 String traits for C-style string ("pointer to const char") More...
 
struct  pqxx::string_traits< const char[N]>
 String traits for "array of const char.". More...
 
struct  pqxx::string_traits< const PGSTD::string >
 
struct  pqxx::string_traits< double >
 
struct  pqxx::string_traits< float >
 
struct  pqxx::string_traits< int >
 
struct  pqxx::string_traits< long >
 
struct  pqxx::string_traits< PGSTD::string >
 
struct  pqxx::string_traits< PGSTD::stringstream >
 
struct  pqxx::string_traits< short >
 
struct  pqxx::string_traits< unsigned int >
 
struct  pqxx::string_traits< unsigned long >
 
struct  pqxx::string_traits< unsigned short >
 

Macros

#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
 

Functions

template<typename T >
void pqxx::from_string (const char Str[], T &Obj)
 Attempt to convert postgres-generated string to given built-in type. More...
 
template<typename T >
void pqxx::from_string (const char Str[], T &Obj, size_t)
 Conversion with known string length (for strings that may contain nuls) More...
 
template<typename T >
void pqxx::from_string (const PGSTD::string &Str, T &Obj)
 
template<typename T >
void pqxx::from_string (const PGSTD::stringstream &Str, T &Obj)
 
template<>
void pqxx::from_string (const PGSTD::string &Str, PGSTD::string &Obj)
 
template<>
void pqxx::from_string< PGSTD::string > (const char Str[], PGSTD::string &Obj, size_t len)
 
template<typename T >
PGSTD::string pqxx::to_string (const T &Obj)
 Convert built-in type to a readable string that PostgreSQL will understand. More...
 

Detailed Description

For purposes of communication with the server, values need to be converted from and to a human-readable string format that (unlike the various functions and templates in the C and C++ standard libraries) is not sensitive to locale settings and internationalization.

This section contains functionality that is used extensively by libpqxx itself, but is also available for use by other programs.

Macro Definition Documentation

#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION (   T)
Value:
template<> struct PQXX_LIBEXPORT string_traits<T> \
{ \
typedef T subject_type; \
static const char *name() { return #T; } \
static bool has_null() { return false; } \
static bool is_null(T) { return false; } \
static T null() \
{ internal::throw_null_conversion(name()); return subject_type(); } \
static void from_string(const char Str[], T &Obj); \
static PGSTD::string to_string(T Obj); \
};

Function Documentation

template<typename T >
void pqxx::from_string ( const char  Str[],
T &  Obj 
)
inline

Attempt to convert postgres-generated string to given built-in type.

If the form of the value found in the string does not match the expected type, e.g. if a decimal point is found when converting to an integer type, the conversion fails. Overflows (e.g. converting "9999999999" to a 16-bit C++ type) are also treated as errors. If in some cases this behaviour should be inappropriate, convert to something bigger such as long int first and then truncate the resulting value.

Only the simplest possible conversions are supported. No fancy features such as hexadecimal or octal, spurious signs, or exponent notation will work. No whitespace is stripped away. Only the kinds of strings that come out of PostgreSQL and out of to_string() can be converted.

References pqxx::from_string().

Here is the call graph for this function:

template<typename T >
void pqxx::from_string ( const char  Str[],
T &  Obj,
size_t   
)
inline

Conversion with known string length (for strings that may contain nuls)

This is only used for strings, where embedded nul bytes should not determine the end of the string.

For all other types, this just uses the regular, nul-terminated version of from_string().

References pqxx::from_string().

Here is the call graph for this function:

template<typename T >
void pqxx::from_string ( const PGSTD::string &  Str,
T &  Obj 
)
inline

References pqxx::from_string().

Here is the call graph for this function:

template<typename T >
void pqxx::from_string ( const PGSTD::stringstream &  Str,
T &  Obj 
)
inline

References pqxx::from_string().

Here is the call graph for this function:

template<>
void pqxx::from_string ( const PGSTD::string &  Str,
PGSTD::string &  Obj 
)
inline
template<>
void pqxx::from_string< PGSTD::string > ( const char  Str[],
PGSTD::string &  Obj,
size_t  len 
)
inline
template<typename T >
PGSTD::string pqxx::to_string ( const T &  Obj)
inline

Convert built-in type to a readable string that PostgreSQL will understand.

No special formatting is done, and any locale settings are ignored. The resulting string will be human-readable and in a format suitable for use in SQL queries.

References pqxx::to_string().

Here is the call graph for this function: