PageRenderTime 2541ms CodeModel.GetById 2527ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/pq/result.h

http://github.com/mozy/mordor
C Header | 79 lines | 44 code | 15 blank | 20 comment | 0 complexity | 86c3b24876d0f4e0e53c0c96893f3ba9 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_PQ_RESULT_H__
  2. #define __MORDOR_PQ_RESULT_H__
  3. // Copyright (c) 2010 - Mozy, Inc.
  4. #include <boost/shared_ptr.hpp>
  5. #include <libpq-fe.h>
  6. namespace Mordor {
  7. namespace PQ {
  8. class Connection;
  9. class PreparedStatement;
  10. class Result
  11. {
  12. friend class Connection;
  13. friend class PreparedStatement;
  14. private:
  15. Result(boost::shared_ptr<PGresult> result)
  16. : m_result(result)
  17. {}
  18. public:
  19. Result() {}
  20. public:
  21. size_t rows() const;
  22. size_t columns() const;
  23. size_t column(const char *name) const;
  24. size_t column(const std::string &name) const
  25. { return column(name.c_str()); }
  26. Oid getType(size_t column) const;
  27. Oid getType(const char *col) const
  28. { return getType(column(col)); }
  29. Oid getType(const std::string &col) const
  30. { return getType(column(col)); }
  31. bool getIsNull(size_t row, size_t column) const;
  32. bool getIsNull(size_t row, const char *col) const
  33. { return getIsNull(row, column(col)); }
  34. bool getIsNull(size_t row, const std::string &col) const
  35. { return getIsNull(row, column(col)); }
  36. /// Get the value of a cell
  37. ///
  38. /// Supported overloads:
  39. /// * std::string (bytea, text, <any>)
  40. /// * const char * (bytea, text, <any>)
  41. /// * bool (boolean)
  42. /// * char (char)
  43. /// * long long (bigint)
  44. /// * short (smallint)
  45. /// * int (integer)
  46. /// * float (real)
  47. /// * double (double precision)
  48. /// * boost::posix_time::ptime (timestamp)
  49. /// * std::vector<int> (integer[])
  50. /// * std::pair<IPAddress::ptr, unsigned int> (inet, cidr)
  51. /// * IPAddress::ptr (inet, cidr)
  52. /// @note Except for the string overloads, these will all ASSERT if the
  53. /// value is NULL. Additionally, the integer[] will also ASSERT if
  54. /// any of the values within the array are NULL.
  55. template <class T> T get(size_t row, size_t column) const;
  56. template <class T> T get(size_t row, const char* col) const
  57. { return get<T>(row, column(col)); }
  58. template <class T> T get(size_t row, const std::string & col) const
  59. { return get<T>(row, column(col)); }
  60. private:
  61. boost::shared_ptr<PGresult> m_result;
  62. };
  63. }}
  64. #endif