Changeset 1363
- Timestamp:
- 08/08/08 23:56:06 (5 months ago)
- Files:
-
- trunk/test/test085.cxx (modified) (1 diff)
- trunk/test/test_helpers.hxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/test/test085.cxx
r1359 r1363 20 20 "Executing " name " as prepared statement yields different results.") \ 21 21 PQXX_CHECK_EQUAL(lhs.empty(), false, "Result for " name " is empty.") 22 23 24 namespace25 {26 /// Dereference result element as string27 struct deref_field28 {29 string operator()(const result::field &f) const { return f.c_str(); }30 };31 }32 33 namespace pqxx34 {35 // Support string conversion for result objects for debug output.36 template<> struct string_traits<result>37 {38 static const char *name() { return "pqxx::result"; }39 static bool has_null() { return true; }40 static bool is_null(result r) { return r.empty(); }41 static result null() { return result(); }42 static void from_string(const char Str[], result &Obj); // Not needed43 static string to_string(result Obj)44 {45 if (is_null(Obj)) return "<empty>";46 47 string out;48 for (result::const_iterator row = Obj.begin(); row != Obj.end(); ++row)49 {50 out += "{" +51 separated_list(", ", row.begin(), row.end(), deref_field()) +52 "}";53 }54 return out;55 }56 };57 }58 22 59 23 trunk/test/test_helpers.hxx
r1361 r1363 202 202 203 203 } // namespace test 204 205 206 namespace 207 { 208 PGSTD::string deref_field(const result::field &f) { return f.c_str(); } 209 } // namespace 210 211 212 // Support string conversion on result objects for debug output. 213 template<> struct string_traits<result> 214 { 215 static const char *name() { return "pqxx::result"; } 216 static bool has_null() { return true; } 217 static bool is_null(result r) { return r.empty(); } 218 static result null() { return result(); } 219 static void from_string(const char Str[], result &Obj); // Not needed 220 static PGSTD::string to_string(result Obj) 221 { 222 if (is_null(Obj)) return "<empty>"; 223 224 PGSTD::string out; 225 for (result::const_iterator row = Obj.begin(); row != Obj.end(); ++row) 226 { 227 out += "{" + 228 separated_list(", ", row.begin(), row.end(), deref_field) + 229 "}"; 230 } 231 return out; 232 } 233 }; 234 235 // Support string conversion on vector<string> for debug output. 236 template<> struct string_traits<PGSTD::vector<PGSTD::string> > 237 { 238 typedef PGSTD::vector<PGSTD::string> subject_type; 239 static const char *name() { return "vector<string>"; } 240 static bool has_null() { return false; } 241 static bool is_null(subject_type) { return false; } 242 static subject_type null(); // Not needed 243 static void from_string(const char Str[], subject_type &Obj); // Not needed 244 static PGSTD::string to_string(const subject_type &Obj) 245 { return separated_list("; ", Obj); } 246 }; 204 247 } // namespace pqxx 205 248
