18 #ifndef PQXX_H_STRINGCONV
19 #define PQXX_H_STRINGCONV
21 #include "pqxx/compiler-public.hxx"
52 const std::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 std::string to_string(T Obj); \
83 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION
88 static const char *
name() {
return "const char *"; }
90 static bool is_null(
const char *t) {
return !t; }
91 static const char *
null() {
return NULL; }
92 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
93 static std::string
to_string(
const char *Obj) {
return Obj; }
99 static const char *
name() {
return "char *"; }
101 static bool is_null(
const char *t) {
return !t; }
102 static const char *
null() {
return NULL; }
113 static const char *
name() {
return "char[]"; }
115 static bool is_null(
const char t[]) {
return !t; }
116 static const char *
null() {
return NULL; }
117 static std::string
to_string(
const char Obj[]) {
return Obj; }
126 static const char *
name() {
return "char[]"; }
128 static bool is_null(
const char t[]) {
return !t; }
129 static const char *
null() {
return NULL; }
130 static std::string
to_string(
const char Obj[]) {
return Obj; }
136 static const char *
name() {
return "string"; }
138 static bool is_null(
const std::string &) {
return false; }
141 static void from_string(
const char Str[], std::string &Obj) { Obj=Str; }
142 static std::string
to_string(
const std::string &Obj) {
return Obj; }
147 static const char *
name() {
return "const string"; }
149 static bool is_null(
const std::string &) {
return false; }
150 static const std::string
null()
152 static const std::string
to_string(
const std::string &Obj) {
return Obj; }
157 static const char *
name() {
return "stringstream"; }
159 static bool is_null(
const std::stringstream &) {
return false; }
160 static std::stringstream
null()
167 { Obj.clear(); Obj << Str; }
168 static std::string
to_string(
const std::stringstream &Obj)
169 {
return Obj.str(); }
192 throw std::runtime_error(
"Attempt to read NULL string");
204 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
210 inline void from_string<std::string>(
const char Str[],
215 throw std::runtime_error(
"Attempt to read NULL string");
216 Obj.assign(Str, len);
227 template<>
inline void
237 {
return static_cast<char>(i+
'0'); }
246 template<
typename T>
inline std::string
to_string(
const T &Obj)
static const char * name()
Definition: strconv.hxx:113
static const char * null()
Definition: strconv.hxx:116
static std::string to_string(char *Obj)
Definition: strconv.hxx:107
static const char * name()
Definition: strconv.hxx:126
static const char * name()
Definition: strconv.hxx:99
int digit_to_number(char c) PQXX_NOEXCEPT
Compute numeric value of given textual digit (assuming that it is a digit)
Definition: strconv.hxx:235
static bool has_null()
Definition: strconv.hxx:100
static std::string to_string(const std::stringstream &Obj)
Definition: strconv.hxx:168
static std::string to_string(const char *Obj)
Definition: strconv.hxx:93
static bool is_null(const std::string &)
Definition: strconv.hxx:149
static bool is_null(const std::stringstream &)
Definition: strconv.hxx:159
#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
Definition: strconv.hxx:55
static const char * name()
Definition: strconv.hxx:157
static const char * null()
Definition: strconv.hxx:129
static bool is_null(const char t[])
Definition: strconv.hxx:128
static std::string null()
Definition: strconv.hxx:139
static const char * null()
Definition: strconv.hxx:102
static const char * name()
Definition: strconv.hxx:136
static std::string to_string(const char Obj[])
Definition: strconv.hxx:117
static const std::string to_string(const std::string &Obj)
Definition: strconv.hxx:152
static bool is_null(const std::string &)
Definition: strconv.hxx:138
static void from_string(const char Str[], const char *&Obj)
Definition: strconv.hxx:92
static const std::string null()
Definition: strconv.hxx:150
PQXX_NORETURN void throw_null_conversion(const std::string &type)
Throw exception for attempt to convert null to given type.
Definition: strconv.cxx:302
static const char * null()
Definition: strconv.hxx:91
static bool has_null()
Definition: strconv.hxx:148
static bool is_null(const char t[])
Definition: strconv.hxx:115
static const char * name()
Definition: strconv.hxx:88
static std::stringstream null()
Definition: strconv.hxx:160
static const char * name()
Definition: strconv.hxx:147
Traits class for use in string conversions.
Definition: strconv.hxx:46
static bool has_null()
Definition: strconv.hxx:127
std::string to_string(const T &Obj)
Convert built-in type to a readable string that PostgreSQL will understand.
Definition: strconv.hxx:246
static std::string to_string(const std::string &Obj)
Definition: strconv.hxx:142
char number_to_digit(int i) PQXX_NOEXCEPT
Definition: strconv.hxx:236
static std::string to_string(const char Obj[])
Definition: strconv.hxx:130
static void from_string(const char Str[], std::string &Obj)
Definition: strconv.hxx:141
static void from_string(const char Str[], std::stringstream &Obj)
Definition: strconv.hxx:166
static bool has_null()
Definition: strconv.hxx:114
static bool is_null(const char *t)
Definition: strconv.hxx:90
static bool has_null()
Definition: strconv.hxx:158
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: result.hxx:459
static bool is_null(const char *t)
Definition: strconv.hxx:101
void from_string(const char Str[], T &Obj)
Attempt to convert postgres-generated string to given built-in type.
Definition: strconv.hxx:189
static bool has_null()
Definition: strconv.hxx:89
static bool has_null()
Definition: strconv.hxx:137
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.hxx:464