libpqxx
The C++ client library for PostgreSQL
strconv.hxx File Reference
#include <algorithm>
#include <charconv>
#include <cstring>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <typeinfo>
#include "pqxx/except.hxx"
#include "pqxx/util.hxx"
#include "pqxx/zview.hxx"
#include "pqxx/internal/conversions.hxx"

Go to the source code of this file.

Classes

struct  pqxx::nullness< TYPE, ENABLE >
 Traits describing a type's "null value," if any. More...
 
struct  pqxx::no_null< TYPE >
 Nullness traits describing a type which does not have a null value. More...
 
struct  pqxx::string_traits< TYPE >
 Traits class for use in string conversions. More...
 
struct  pqxx::forbidden_conversion< TYPE >
 String traits for a forbidden type conversion. More...
 
struct  pqxx::string_traits< char >
 You cannot convert a char to/from SQL. More...
 
struct  pqxx::string_traits< unsigned char >
 You cannot convert an unsigned char to/from SQL. More...
 
struct  pqxx::string_traits< signed char >
 You cannot convert a signed char to/from SQL. More...
 
struct  pqxx::string_traits< std::byte >
 You cannot convert a std::byte to/from SQL. More...
 
struct  pqxx::nullness< ENUM, std::enable_if_t< std::is_enum_v< ENUM > > >
 Nullness: Enums do not have an inherent null value. More...
 
struct  pqxx::internal::enum_traits< ENUM >
 Helper class for defining enum conversions. More...
 

Namespaces

 pqxx
 The home of all libpqxx classes, functions, templates, etc.
 
 pqxx::internal
 Internal items for libpqxx' own use. Do not use these yourself.
 

Macros

#define PQXX_DECLARE_ENUM_CONVERSION(ENUM)
 Macro: Define a string conversion for an enum type. More...
 

Functions

template<typename TYPE >
void pqxx::oops_forbidden_conversion () noexcept
 Nonexistent function to indicate a disallowed type conversion. More...
 
template<typename TYPE >
TYPE pqxx::from_string (std::string_view text)
 Parse a value in postgres' text format as a TYPE. More...
 
template<>
std::string_view pqxx::from_string (std::string_view text)
 "Convert" a std::string_view to a std::string_view. More...
 
template<typename T >
void pqxx::from_string (std::string_view text, T &value)
 Attempt to convert postgres-generated string to given built-in object. More...
 
template<typename TYPE >
std::string pqxx::to_string (TYPE const &value)
 Convert a value to a readable string that PostgreSQL will understand. More...
 
template<typename... TYPE>
std::vector< std::string_view > pqxx::to_buf (char *here, char const *end, TYPE...value)
 Convert multiple values to strings inside a single buffer. More...
 
template<typename TYPE >
void pqxx::into_string (TYPE const &value, std::string &out)
 Convert a value to a readable string that PostgreSQL will understand. More...
 
template<typename TYPE >
constexpr bool pqxx::is_null (TYPE const &value) noexcept
 Is value null? More...
 
template<typename... TYPE>
std::size_t pqxx::size_buffer (TYPE const &...value) noexcept
 Estimate how much buffer space is needed to represent values as a string. More...
 
template<typename TYPE >
constexpr format pqxx::param_format (TYPE const &)
 What's the preferred format for passing non-null parameters of this type? More...
 
template<typename TYPE >
zview pqxx::generic_to_buf (char *begin, char *end, TYPE const &value)
 Implement string_traits<TYPE>::to_buf by calling into_buf. More...
 

Variables

template<typename TYPE >
constexpr bool pqxx::is_sql_array {false}
 Does this type translate to an SQL array? More...
 
template<typename TYPE >
constexpr bool pqxx::is_unquoted_safe {false}
 Can we use this type in arrays and composite types without quoting them? More...
 
template<typename T >
constexpr char pqxx::array_separator {','}
 Element separator between SQL array elements of this type. More...
 

Macro Definition Documentation

#define PQXX_DECLARE_ENUM_CONVERSION (   ENUM)
Value:
template<> struct string_traits<ENUM> : pqxx::internal::enum_traits<ENUM> \
{}; \
template<> \
inline constexpr PQXX_PURE std::string_view name_type<ENUM>() noexcept \
{ \
return #ENUM; \
} \
template<> [[maybe_unused]] inline std::string_view const type_name<ENUM> \
{ \
#ENUM \
}
#define PQXX_PURE
Declare function "pure": no side effects, only reads globals and its args.
Definition: header-pre.hxx:77
Helper class for defining enum conversions.
Definition: strconv.hxx:339

Macro: Define a string conversion for an enum type.

This specialises the pqxx::string_traits template, so use it in the pqxx namespace.

For example:

 #include <iostream>
 #include <pqxx/strconv>
 enum X { xa, xb };
 namespace pqxx { PQXX_DECLARE_ENUM_CONVERSION(x); }
 int main() { std::cout << pqxx::to_string(xa) << std::endl; }