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

util.hxx File Reference

#include "pqxx/libcompiler.h"
#include <cstdio>
#include <cctype>
#include <sstream>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <vector>
#include <pqxx/libpq-forward.hxx>

Include dependency graph for util.hxx:

Go to the source code of this file.

Namespaces

namespace  pqxx
namespace  pqxx::internal

Typedefs

typedef unsigned long result_size_type
typedef long result_difference_type

Functions

template<typename T>
void error_unsupported_type_in_string_conversion (T)
 Dummy name, used by libpqxx in deliberate link errors.
template<typename T>
PGSTD::string error_ambiguous_string_conversion (T)
 Dummy name, used to generate meaningful link errors.
template<typename T>
void from_string (const char Str[], T &Obj)
 Attempt to convert postgres-generated string to given built-in type.
template<>
void PQXX_LIBEXPORT from_string (const char Str[], long &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], unsigned long &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], int &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], unsigned int &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], short &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], unsigned short &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], float &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], double &)
template<>
void PQXX_LIBEXPORT from_string (const char Str[], bool &)
template<>
void from_string (const char Str[], PGSTD::string &Obj)
template<>
void from_string (const char Str[], PGSTD::stringstream &Obj)
template<typename T>
void from_string (const PGSTD::string &Str, T &Obj)
template<typename T>
void from_string (const PGSTD::stringstream &Str, T &Obj)
template<>
void from_string (const PGSTD::string &Str, PGSTD::string &Obj)
template<>
void from_string (const char[], const char &Obj)
template<>
void from_string (const char[], const signed char &Obj)
template<>
void from_string (const char[], const unsigned char &Obj)
template<>
void from_string (const PGSTD::string &, const char &Obj)
template<>
void from_string (const PGSTD::string &, const signed char &Obj)
template<>
void from_string (const PGSTD::string &, const unsigned char &Obj)
int digit_to_number (char c) throw ()
 Compute numeric value of given textual digit (assuming that it is a digit).
char number_to_digit (int i) throw ()
template<typename T>
PGSTD::string to_string (const T &)
 Convert built-in type to a readable string that PostgreSQL will understand.
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const short &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const unsigned short &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const int &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const unsigned int &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const long &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const unsigned long &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const float &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const double &)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const bool &)
PGSTD::string to_string (const char Obj[])
PGSTD::string to_string (const PGSTD::stringstream &Obj)
PGSTD::string to_string (const PGSTD::string &Obj)
template<>
PGSTD::string PQXX_LIBEXPORT to_string (const char &)
template<>
PGSTD::string to_string (const signed char &Obj)
template<>
PGSTD::string to_string (const unsigned char &Obj)
template<typename ITER, typename ACCESS>
PGSTD::string separated_list (const PGSTD::string &sep, ITER begin, ITER end, ACCESS access)
 Access iterators using ACCESS functor, returning separator-separated list.
template<typename ITER>
PGSTD::string separated_list (const PGSTD::string &sep, ITER begin, ITER end)
 Render sequence as a string, using given separator between items.
template<typename OBJ>
PGSTD::string separated_list (const PGSTD::string &sep, OBJ *begin, OBJ *end)
 Render array as a string, using given separator between items.
template<typename CONTAINER>
PGSTD::string separated_list (const PGSTD::string &sep, const CONTAINER &c)
 Render items in a container as a string, using given separator.
template<typename T>
const char * FmtString (T t)
 C-style format strings for various built-in types.
template<>
const char * FmtString (short)
template<>
const char * FmtString (unsigned short)
template<>
const char * FmtString (int)
template<>
const char * FmtString (long)
template<>
const char * FmtString (float)
template<>
const char * FmtString (double)
template<>
const char * FmtString (char)
template<typename T>
PGSTD::string ToString (const T &Obj)
 Convert object of built-in type to string.
template<>
PGSTD::string ToString (const PGSTD::string &Obj)
template<>
PGSTD::string ToString (const char *const &Obj)
template<>
PGSTD::string ToString (char *const &Obj)
template<>
PGSTD::string ToString (const unsigned char *const &Obj)
template<>
PGSTD::string ToString (const bool &Obj)
template<>
PGSTD::string ToString (const short &Obj)
template<>
PGSTD::string ToString (const unsigned short &Obj)
template<typename T>
void FromString (const char Str[], T &Obj)
 Convert string to object of built-in type.
void PQXX_LIBEXPORT FromString_string (const char Str[], PGSTD::string &Obj)
 For libpqxx internal use only: convert C string to C++ string.
void PQXX_LIBEXPORT FromString_ucharptr (const char Str[], const unsigned char *&Obj)
 For libpqxx internal use only: convert unsigned char * to C++ string.
PGSTD::string PQXX_LIBEXPORT Quote_string (const PGSTD::string &Obj, bool EmptyIsNull)
 For libpqxx internal use only: quote std::string.
PGSTD::string PQXX_LIBEXPORT Quote_charptr (const char Obj[], bool EmptyIsNull)
 For libpqxx internal use only: quote const char *.
template<>
void FromString (const char Str[], PGSTD::string &Obj)
template<>
void FromString (const char Str[], const char *&Obj)
template<>
void FromString (const char Str[], const unsigned char *&Obj)
template<>
void FromString (const char Str[], bool &Obj)
PGSTD::string PQXX_LIBEXPORT sqlesc (const char str[])
 Escape nul-terminated string for inclusion in SQL strings.
PGSTD::string PQXX_LIBEXPORT sqlesc (const char str[], size_t maxlen)
 Escape string for inclusion in SQL strings.
PGSTD::string PQXX_LIBEXPORT sqlesc (const PGSTD::string &)
 Escape string for inclusion in SQL strings.
template<typename T>
PGSTD::string Quote (const T &Obj, bool EmptyIsNull)
 Quote string for use in SQL.
template<>
PGSTD::string Quote (const PGSTD::string &Obj, bool EmptyIsNull)
 std::string version, on which the other versions are built
template<>
PGSTD::string Quote (const char *const &Obj, bool EmptyIsNull)
 Special case for const char *, accepting null pointer as null value.
template<int LEN>
PGSTD::string Quote (const char(&Obj)[LEN], bool EmptyIsNull)
 Specialization for string constants.
template<typename T>
PGSTD::string Quote (T Obj)
 Quote string for use in SQL.
void freepqmem (void *)
void PQXX_LIBEXPORT freemem_result (pq::PGresult *) throw ()
template<>
void PQXX_LIBEXPORT PQAlloc< pq::PGresult >::freemem () throw ()
void PQXX_LIBEXPORT freemem_notif (pq::PGnotify *) throw ()
template<>
void PQXX_LIBEXPORT PQAlloc< pq::PGnotify >::freemem () throw ()
void CheckUniqueRegistration (const namedclass *New, const namedclass *Old)
void CheckUniqueUnregistration (const namedclass *New, const namedclass *Old)
void PQXX_LIBEXPORT sleep_seconds (int)
 Sleep for the given number of seconds.

Variables

const oid oid_none = 0
 The "null" oid.


Typedef Documentation

typedef long pqxx::internal::result_difference_type
 

typedef unsigned long pqxx::internal::result_size_type
 


Function Documentation

void pqxx::internal::CheckUniqueRegistration const namedclass *  New,
const namedclass *  Old
 

void pqxx::internal::CheckUniqueUnregistration const namedclass *  New,
const namedclass *  Old
 

int pqxx::internal::digit_to_number char  c  )  throw ()
 

Compute numeric value of given textual digit (assuming that it is a digit).

template<typename T>
PGSTD::string pqxx::error_ambiguous_string_conversion  ) 
 

Dummy name, used to generate meaningful link errors.

If you get a link error naming this function, this means that your program includes a string conversion involving a signed or unsigned char type. The problem with such conversions is that they are ambiguous: do you want to treat the char type as a small numeric type, or as a character type like plain char?

template<typename T>
void pqxx::error_unsupported_type_in_string_conversion  ) 
 

Dummy name, used by libpqxx in deliberate link errors.

If you get an error involving this function while building your program, this means that the program contains an unsupported string conversion.

In other words, the program tries to convert an object to a string, or a string to an object, of a type for which libpqxx does not implement this conversion. A notable example is "long long," which is supported by many compilers but does not exist in Standard C++.

In the case of "long long" and similar types, if your implementation of the standard C++ library supports it, you may use a stringstream to perform the conversion. For other types, you may have to write the conversion routine yourself.

template<>
const char* pqxx::internal::FmtString char   ) 
 

template<>
const char* pqxx::internal::FmtString double   ) 
 

template<>
const char* pqxx::internal::FmtString float   ) 
 

template<>
const char* pqxx::internal::FmtString long   ) 
 

template<>
const char* pqxx::internal::FmtString int   ) 
 

template<>
const char * pqxx::internal::FmtString unsigned  char  ) 
 

template<>
const char* pqxx::internal::FmtString short   ) 
 

template<typename T>
const char* pqxx::internal::FmtString t  ) 
 

C-style format strings for various built-in types.

Deprecated:
To be removed when ToString and FromString are taken out
Only allowed for certain types, for which this function is explicitly specialized. When attempting to use the template for an unsupported type, the generic version will be instantiated. This will result in a link error for the symbol error_unsupported_type_in_string_conversion(), with a template argument describing the unsupported input type.

void PQXX_LIBEXPORT pqxx::internal::freemem_notif pq::PGnotify  )  throw ()
 

void PQXX_LIBEXPORT pqxx::internal::freemem_result pq::PGresult  )  throw ()
 

void pqxx::internal::freepqmem void *   ) 
 

template<>
void pqxx::from_string const PGSTD::string &  ,
const unsigned char &  Obj
 

template<>
void pqxx::from_string const PGSTD::string &  ,
const signed char &  Obj
 

template<>
void pqxx::from_string const PGSTD::string &  ,
const char &  Obj
 

template<>
void pqxx::from_string const   char[],
const unsigned char &  Obj
 

template<>
void pqxx::from_string const   char[],
const signed char &  Obj
 

template<>
void pqxx::from_string const   char[],
const char &  Obj
 

template<>
void pqxx::from_string const PGSTD::string &  Str,
PGSTD::string &  Obj
 

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

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

template<>
void pqxx::from_string const char  Str[],
PGSTD::stringstream &  Obj
 

template<>
void pqxx::from_string const char  Str[],
PGSTD::string &  Obj
 

template<>
void pqxx::from_string const char  Str[],
bool & 
 

template<>
void pqxx::from_string const char  Str[],
double & 
 

template<>
void pqxx::from_string const char  Str[],
float & 
 

template<>
void pqxx::from_string const char  Str[],
unsigned short & 
 

template<>
void pqxx::from_string const char  Str[],
short & 
 

template<>
void pqxx::from_string const char  Str[],
unsigned int & 
 

template<>
void pqxx::from_string const char  Str[],
int & 
 

template<>
void pqxx::from_string const char  Str[],
unsigned long & 
 

template<>
void pqxx::from_string const char  Str[],
long & 
 

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

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" 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.

template<>
void pqxx::FromString const char  Str[],
bool &  Obj
 

template<>
void pqxx::FromString const char  Str[],
const unsigned char *&  Obj
 

template<>
void pqxx::FromString const char  Str[],
const char *&  Obj
 

template<>
void pqxx::FromString const char  Str[],
PGSTD::string &  Obj
 

template<typename T>
void pqxx::FromString const char  Str[],
T &  Obj
 

Convert string to object of built-in type.

Deprecated:
Use the stricter, safer from_string instead.
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. This problem does not exist with the newer from_string function template.

void PQXX_LIBEXPORT pqxx::internal::FromString_string const char  Str[],
PGSTD::string &  Obj
 

For libpqxx internal use only: convert C string to C++ string.

Deprecated:
To be removed when FromString is taken out

void PQXX_LIBEXPORT pqxx::internal::FromString_ucharptr const char  Str[],
const unsigned char *&  Obj
 

For libpqxx internal use only: convert unsigned char * to C++ string.

Deprecated:
To be removed when FromString is taken out

char pqxx::internal::number_to_digit int  i  )  throw ()
 

template<>
void PQXX_LIBEXPORT pqxx::internal::PQAlloc< pq::PGnotify >::freemem  )  throw ()
 

template<>
void PQXX_LIBEXPORT pqxx::internal::PQAlloc< pq::PGresult >::freemem  )  throw ()
 

template<typename T>
PGSTD::string pqxx::Quote Obj  ) 
 

Quote string for use in SQL.

This version of the function never generates null values.

Deprecated:
Use sqlesc instead.

template<int LEN>
PGSTD::string pqxx::Quote const char &  Obj[LEN],
bool  EmptyIsNull
 

Specialization for string constants.

This specialization is a little complicated, because string constants are of the type char[], not of type const char * as one might expect. Note that the size of the array is part of the type, for which reason we need it in our template here.

template<>
PGSTD::string pqxx::Quote const char *const &  Obj,
bool  EmptyIsNull
 

Special case for const char *, accepting null pointer as null value.

Deprecated:
Use sqlesc instead.

template<>
PGSTD::string pqxx::Quote const PGSTD::string &  Obj,
bool  EmptyIsNull
 

std::string version, on which the other versions are built

Deprecated:
Use sqlesc instead.

template<typename T>
PGSTD::string pqxx::Quote const T &  Obj,
bool  EmptyIsNull
 

Quote string for use in SQL.

Generate SQL-quoted version of string. If EmptyIsNull is set, an empty string will generate the null value rather than an empty string.

Deprecated:
Use sqlesc instead.

PGSTD::string PQXX_LIBEXPORT pqxx::internal::Quote_charptr const char  Obj[],
bool  EmptyIsNull
 

For libpqxx internal use only: quote const char *.

PGSTD::string PQXX_LIBEXPORT pqxx::internal::Quote_string const PGSTD::string &  Obj,
bool  EmptyIsNull
 

For libpqxx internal use only: quote std::string.

template<typename CONTAINER>
PGSTD::string pqxx::separated_list const PGSTD::string &  sep,
const CONTAINER &  c
 

Render items in a container as a string, using given separator.

template<typename OBJ>
PGSTD::string pqxx::separated_list const PGSTD::string &  sep,
OBJ *  begin,
OBJ *  end
 

Render array as a string, using given separator between items.

template<typename ITER>
PGSTD::string pqxx::separated_list const PGSTD::string &  sep,
ITER  begin,
ITER  end
 

Render sequence as a string, using given separator between items.

template<typename ITER, typename ACCESS>
PGSTD::string pqxx::separated_list const PGSTD::string &  sep,
ITER  begin,
ITER  end,
ACCESS  access
 

Access iterators using ACCESS functor, returning separator-separated list.

void PQXX_LIBEXPORT pqxx::internal::sleep_seconds int   ) 
 

Sleep for the given number of seconds.

May return early, e.g. when interrupted by a signal. Completes instantly if a zero or negative sleep time is requested.

PGSTD::string PQXX_LIBEXPORT pqxx::sqlesc const PGSTD::string &   ) 
 

Escape string for inclusion in SQL strings.

This function differs from similar ones based on libpq in that it handles embedded nul bytes correctly.

Unlike its predecessor Quote(), this function does not add SQL-style single quotes around the result string; nor does it recognize and generate nulls.

PGSTD::string PQXX_LIBEXPORT pqxx::sqlesc const char  str[],
size_t  maxlen
 

Escape string for inclusion in SQL strings.

Reads and escapes input string. The string is terminated by either a nul character or the given byte length, whichever comes first.

Parameters:
str optionally zero-terminated character string
maxlen largest possible length of input string, not including optional terminating nul character.
Unlike its predecessor Quote(), this function does not add SQL-style single quotes around the result string; nor does it recognize and generate nulls.

PGSTD::string PQXX_LIBEXPORT pqxx::sqlesc const char  str[]  ) 
 

Escape nul-terminated string for inclusion in SQL strings.

Use this to sanitize strings that may contain characters like backslashes or quotes. You'll want to do this for all data received from outside your application that gets used in SQL--otherwise an attacker might crack your code by feeding it some string containing e.g. a closing quote followed by SQL commands you did not intend to execute.

Unlike its predecessor Quote(), this function does not add SQL-style single quotes around the result string; nor does it recognize and generate nulls.

template<>
PGSTD::string pqxx::to_string const unsigned char &  Obj  ) 
 

template<>
PGSTD::string pqxx::to_string const signed char &  Obj  ) 
 

template<>
string pqxx::to_string const char &   ) 
 

PGSTD::string pqxx::to_string const PGSTD::string &  Obj  ) 
 

PGSTD::string pqxx::to_string const PGSTD::stringstream &  Obj  ) 
 

PGSTD::string pqxx::to_string const char  Obj[]  ) 
 

template<>
string pqxx::to_string const bool &   ) 
 

template<>
string pqxx::to_string const double &   ) 
 

template<>
string pqxx::to_string const float &   ) 
 

template<>
string pqxx::to_string const unsigned long &   ) 
 

template<>
string pqxx::to_string const long &   ) 
 

template<>
string pqxx::to_string const unsigned int &   ) 
 

template<>
string pqxx::to_string const int &   ) 
 

template<>
string pqxx::to_string const unsigned short &   ) 
 

template<>
string pqxx::to_string const short &   ) 
 

template<typename T>
PGSTD::string pqxx::to_string const T &   ) 
 

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.

template<>
PGSTD::string pqxx::ToString const unsigned short &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString const short &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString const bool &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString const unsigned char *const &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString char *const &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString const char *const &  Obj  ) 
 

template<>
PGSTD::string pqxx::ToString const PGSTD::string &  Obj  ) 
 

template<typename T>
PGSTD::string pqxx::ToString const T &  Obj  ) 
 

Convert object of built-in type to string.

Deprecated:
Use the newer, rewritten to_string instead.
Warning:
The conversion is done using the currently active locale, whereas PostgreSQL expects values in the "default" (C) locale. This means that if you intend to use this function from a locale that renders the data types in question (particularly numeric types like float and int) differently from the C default, you'll need to switch back to the C locale before the call. This problem does not exist with the newer to_string function template.


Variable Documentation

const oid pqxx::oid_none = 0
 

The "null" oid.


Generated on Fri Jul 1 14:36:20 2005 for libpqxx by  doxygen 1.4.2