Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef RETTYPES_H_
00009 #define RETTYPES_H_
00010
00011 #include <tuple>
00012 #include <libpqtypes.h>
00013 #include "PqTypeWrap.h"
00014 #include "PgSqlException.h"
00015
00016 namespace psql
00017 {
00018
00019 template<typename... Tail>
00020 class RetTypes
00021 {};
00022
00023 template<typename Head, typename... Tail>
00024 class RetTypes<Head, Tail...> : private RetTypes<Tail...>
00025 {
00026 private:
00027 PqTypeWrap<Head> tw;
00028 protected:
00029 std::tuple<Head, Tail...> get_values_prot(PGresult* res, int row, int col)
00030 {
00031 return std::tuple_cat(std::make_tuple(tw.get(res, row, col)), RetTypes<Tail...>::get_values_prot(res, row, col + 1));
00032 }
00033 public:
00034 typedef std::tuple<Head, Tail...> RowType;
00035
00036 RowType get_values(PGresult* res, int row)
00037 {
00038 return get_values_prot(res, row, 0);
00039 }
00040 };
00041
00042 template<>
00043 class RetTypes<>
00044 {
00045 protected:
00046 std::tuple<> get_values_prot(PGresult* res, int, int col)
00047 {
00048 if (PQnfields(res) != col)
00049 throw PgSqlException("Statement not retrieving all data in result");
00050 return std::tuple<>();
00051 }
00052 public:
00053 typedef std::tuple<> RowType;
00054
00055 RowType get_values(PGresult*, int)
00056 {
00057 return std::tuple<>();
00058 }
00059 };
00060
00061 }
00062 #endif