18 #ifndef PQXX_H_STRINGCONV
19 #define PQXX_H_STRINGCONV
21 #include "pqxx/compiler-public.hxx"
52 const PGSTD::string &type);
55 #define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T) \
56 template<> struct PQXX_LIBEXPORT string_traits<T> \
58 typedef T subject_type; \
59 static const char *name() { return #T; } \
60 static bool has_null() { return false; } \
61 static bool is_null(T) { return false; } \
63 { internal::throw_null_conversion(name()); return subject_type(); } \
64 static void from_string(const char Str[], T &Obj); \
65 static PGSTD::string to_string(T Obj); \
76 #ifdef PQXX_HAVE_LONG_LONG
83 #ifdef PQXX_HAVE_LONG_DOUBLE
87 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION
92 static const char *
name() {
return "const char *"; }
94 static bool is_null(
const char *t) {
return !t; }
95 static const char *
null() {
return NULL; }
96 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
97 static PGSTD::string
to_string(
const char *Obj) {
return Obj; }
103 static const char *
name() {
return "char *"; }
105 static bool is_null(
const char *t) {
return !t; }
106 static const char *
null() {
return NULL; }
111 static PGSTD::string
to_string(
char *Obj) {
return Obj; }
117 static const char *
name() {
return "char[]"; }
119 static bool is_null(
const char t[]) {
return !t; }
120 static const char *
null() {
return NULL; }
121 static PGSTD::string
to_string(
const char Obj[]) {
return Obj; }
130 static const char *
name() {
return "char[]"; }
132 static bool is_null(
const char t[]) {
return !t; }
133 static const char *
null() {
return NULL; }
134 static PGSTD::string
to_string(
const char Obj[]) {
return Obj; }
140 static const char *
name() {
return "string"; }
142 static bool is_null(
const PGSTD::string &) {
return false; }
145 static void from_string(
const char Str[], PGSTD::string &Obj) { Obj=Str; }
146 static PGSTD::string
to_string(
const PGSTD::string &Obj) {
return Obj; }
151 static const char *
name() {
return "const string"; }
153 static bool is_null(
const PGSTD::string &) {
return false; }
154 static const PGSTD::string
null()
156 static const PGSTD::string
to_string(
const PGSTD::string &Obj) {
return Obj; }
161 static const char *
name() {
return "stringstream"; }
163 static bool is_null(
const PGSTD::stringstream &) {
return false; }
164 static PGSTD::stringstream
null()
170 static void from_string(
const char Str[], PGSTD::stringstream &Obj)
171 { Obj.clear(); Obj << Str; }
172 static PGSTD::string
to_string(
const PGSTD::stringstream &Obj)
173 {
return Obj.str(); }
196 throw PGSTD::runtime_error(
"Attempt to read NULL string");
208 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
214 inline void from_string<PGSTD::string>(
const char Str[],
219 throw PGSTD::runtime_error(
"Attempt to read NULL string");
220 Obj.assign(Str, len);
231 template<>
inline void
249 template<
typename T>
inline PGSTD::string
to_string(
const T &Obj)
static std::stringstream null()
Definition: strconv.hxx:164
static std::string to_string(const std::string &Obj)
Definition: strconv.hxx:146
Traits class for use in string conversions.
Definition: strconv.hxx:46
static bool has_null()
Definition: strconv.hxx:162
static bool has_null()
Definition: strconv.hxx:152
void from_string(const std::string &Str, std::string &Obj)
Definition: strconv.hxx:232
static bool has_null()
Definition: strconv.hxx:93
static std::string to_string(char *Obj)
Definition: strconv.hxx:111
static const char * name()
Definition: strconv.hxx:130
static const char * name()
Definition: strconv.hxx:103
static const char * null()
Definition: strconv.hxx:133
static bool is_null(const std::string &)
Definition: strconv.hxx:153
static const char * name()
Definition: strconv.hxx:117
The home of all libpqxx classes, functions, templates, etc.
Definition: basic_connection.hxx:35
static const std::string to_string(const std::string &Obj)
Definition: strconv.hxx:156
static bool is_null(const std::string &)
Definition: strconv.hxx:142
char number_to_digit(int i)
Definition: strconv.hxx:240
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: result.hxx:462
static bool has_null()
Definition: strconv.hxx:131
static bool is_null(const char *t)
Definition: strconv.hxx:94
static std::string to_string(const char *Obj)
Definition: strconv.hxx:97
static const char * name()
Definition: strconv.hxx:92
static bool is_null(const char t[])
Definition: strconv.hxx:132
static std::string null()
Definition: strconv.hxx:143
static bool is_null(const std::stringstream &)
Definition: strconv.hxx:163
static bool has_null()
Definition: strconv.hxx:104
static std::string to_string(const char Obj[])
Definition: strconv.hxx:121
static void from_string(const char Str[], std::stringstream &Obj)
Definition: strconv.hxx:170
static bool has_null()
Definition: strconv.hxx:141
int digit_to_number(char c)
Compute numeric value of given textual digit (assuming that it is a digit)
Definition: strconv.hxx:239
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.hxx:467
static std::string to_string(const char Obj[])
Definition: strconv.hxx:134
static void from_string(const char Str[], std::string &Obj)
Definition: strconv.hxx:145
static const char * name()
Definition: strconv.hxx:151
static const char * null()
Definition: strconv.hxx:120
std::string to_string(const T &Obj)
Convert built-in type to a readable string that PostgreSQL will understand.
Definition: strconv.hxx:249
static const char * name()
Definition: strconv.hxx:161
static const std::string null()
Definition: strconv.hxx:154
static void from_string(const char Str[], const char *&Obj)
Definition: strconv.hxx:96
static const char * name()
Definition: strconv.hxx:140
static bool is_null(const char t[])
Definition: strconv.hxx:119
static const char * null()
Definition: strconv.hxx:95
#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
Definition: strconv.hxx:55
static bool has_null()
Definition: strconv.hxx:118
static const char * null()
Definition: strconv.hxx:106
static bool is_null(const char *t)
Definition: strconv.hxx:105
void PQXX_NORETURN throw_null_conversion(const std::string &type)
Throw exception for attempt to convert null to given type.
Definition: strconv.cxx:353
static std::string to_string(const std::stringstream &Obj)
Definition: strconv.hxx:172