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