20 #ifdef RIPPLED_REPORTING
21 #ifndef RIPPLE_CORE_PG_H_INCLUDED
22 #define RIPPLE_CORE_PG_H_INCLUDED
24 #include <ripple/basics/BasicConfig.h>
25 #include <ripple/basics/Log.h>
26 #include <ripple/protocol/Protocol.h>
27 #include <boost/lexical_cast.hpp>
97 pg_result_type result_{
nullptr, [](PGresult* result) { PQclear(result); }};
112 explicit PgResult(pg_result_type&& result) : result_(
std::move(result))
121 PgResult(PGresult* result, PGconn* conn)
122 : error_({PQresultStatus(result), PQerrorMessage(conn)})
137 c_str(
int ntuple = 0,
int nfield = 0)
const
139 return PQgetvalue(result_.get(), ntuple, nfield);
153 asInt(
int ntuple = 0,
int nfield = 0)
const
155 return boost::lexical_cast<std::int32_t>(
156 PQgetvalue(result_.get(), ntuple, nfield));
170 asBigInt(
int ntuple = 0,
int nfield = 0)
const
172 return boost::lexical_cast<std::int64_t>(
173 PQgetvalue(result_.get(), ntuple, nfield));
186 isNull(
int ntuple = 0,
int nfield = 0)
const
188 return PQgetisnull(result_.get(), ntuple, nfield);
195 operator bool()
const
197 return result_ !=
nullptr;
220 return PQntuples(result_.get());
233 return PQnfields(result_.get());
246 return PQresultStatus(result_.get());
254 friend class PgQuery;
256 PgConfig
const& config_;
262 pg_connection_type conn_{
nullptr, [](PGconn* conn) { PQfinish(conn); }};
305 query(
char const* command,
std::size_t nParams,
char const*
const* values);
313 query(
char const* command)
315 return query(command, 0,
nullptr);
324 query(pg_params
const& dbParams);
334 bulkInsert(
char const* table,
std::string const& records);
344 Pg(PgConfig
const& config,
348 : config_(config), j_(j), stop_(stop), mutex_(mutex)
370 friend class PgQuery;
449 : pool_(pool), pg_(pool->checkout())
464 operator()(pg_params
const& dbParams)
468 return pg_->query(dbParams);
477 operator()(
char const* command)
479 return operator()(pg_params{command, {}});
490 bulkInsert(
char const* table,
std::string const& records)
492 pg_->bulkInsert(table, records);
519 #endif // RIPPLE_CORE_PG_H_INCLUDED
520 #endif // RIPPLED_REPORTING