# String conversion

## Namespaces

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

## Functions

template<typename T>
void | pqxx::error_unsupported_type_in_string_conversion (T)
| Dummy name, used by libpqxx in deliberate link errors.
template<typename T>
PGSTD::string | pqxx::error_ambiguous_string_conversion (T)
| Dummy name, used to generate meaningful link errors.
template<typename T>
void | pqxx::from_string (const char Str[], T &Obj)
| Attempt to convert postgres-generated string to given built-in type.
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).
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], PGSTD::string &, size_t)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], long &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], unsigned long &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], int &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], unsigned int &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], short &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], unsigned short &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], float &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], double &)
template<>
void PQXX_LIBEXPORT | pqxx::from_string (const char Str[], bool &)
template<>
void | pqxx::from_string (const char Str[], PGSTD::string &Obj)
template<>
void | pqxx::from_string (const char Str[], PGSTD::stringstream &Obj)
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 (const char[], char &Obj)
template<>
void | pqxx::from_string (const char[], signed char &Obj)
template<>
void | pqxx::from_string (const char[], unsigned char &Obj)
template<>
void | pqxx::from_string (const PGSTD::string &, char &Obj)
template<>
void | pqxx::from_string (const PGSTD::string &, signed char &Obj)
template<>
void | pqxx::from_string (const PGSTD::string &, unsigned char &Obj)
template<typename T>
PGSTD::string | pqxx::to_string (const T &)
| Convert built-in type to a readable string that PostgreSQL will understand.
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const short &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const unsigned short &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const int &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const unsigned int &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const long &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const unsigned long &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const float &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const double &)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const bool &)
PGSTD::string | pqxx::to_string (const char Obj[])
PGSTD::string | pqxx::to_string (const PGSTD::stringstream &Obj)
PGSTD::string | pqxx::to_string (const PGSTD::string &Obj)
template<>
PGSTD::string PQXX_LIBEXPORT | pqxx::to_string (const char &)
template<>
PGSTD::string | pqxx::to_string (const signed char &Obj)
template<>
PGSTD::string | pqxx::to_string (const unsigned char &Obj)

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

Some conversions are considered to be ambiguous. An example is the conversion between `char` and string: is the `char` intended as a character (in which case there are easier ways to accomplish the conversion), or is it being used as merely a very small integral type? And in the latter case, what range is it expected to have--signed, unsigned, or only the range that those two share? An ambiguous conversion attempt will result in a build error, typically a linker message complaining about a missing function whose name starts with "<tt>error_</tt>". Such errors are always deliberately generated. When you see one, look up the documentation for the function it names.

## Function Documentation

template<typename T>

PGSTD::string pqxx::error_ambiguous_string_conversion | ( | T |  | ) |

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 | ( | T |  | ) |

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 "<tt>long long</tt>," which is supported by many compilers but does not exist in Standard C++.

In the case of "<tt>long long</tt>" 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<>

void pqxx::from_string | ( | const PGSTD::string & | ,
|  | unsigned char & | Obj |
| ) |  |  |

template<>

void pqxx::from_string | ( | const PGSTD::string & | ,
|  | signed char & | Obj |
| ) |  |  |

template<>

void pqxx::from_string | ( | const PGSTD::string & | ,
|  | char & | Obj |
| ) |  |  |

template<>

void pqxx::from_string | ( | const | char[],
|  | unsigned char & | Obj |
| ) |  |  |

template<>

void pqxx::from_string | ( | const | char[],
|  | signed char & | Obj |
| ) |  |  |

template<>

void pqxx::from_string | ( | const | char[],
|  | 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<>

void pqxx::from_string | ( | const char | Str[],
|  | PGSTD::string & | ,
|  | size_t |  |
| ) |  |  |

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

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().

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

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.