From a221fb5615c6f174d5db463f69377c0829f449ab Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Feb 2016 20:47:35 +0000 Subject: Prepare statement upfront during construction --- libpqpp/pq-modifycommand.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libpqpp/pq-modifycommand.cpp') diff --git a/libpqpp/pq-modifycommand.cpp b/libpqpp/pq-modifycommand.cpp index e59908e..e140f0a 100644 --- a/libpqpp/pq-modifycommand.cpp +++ b/libpqpp/pq-modifycommand.cpp @@ -7,7 +7,7 @@ PQ::ModifyCommand::ModifyCommand(Connection * conn, const std::string & sql, uns DB::Command(sql), DB::ModifyCommand(sql), PQ::Command(conn, sql, no), - hash(std::hash()(sql)) + pstmt(prepare()->second) { } @@ -18,6 +18,7 @@ PQ::ModifyCommand::~ModifyCommand() PQ::Connection::PreparedStatements::const_iterator PQ::ModifyCommand::prepare() const { + auto hash(std::hash()(sql)); auto i = c->preparedStatements.find(hash); if (i != c->preparedStatements.end()) { return i; @@ -33,7 +34,7 @@ PQ::ModifyCommand::prepare() const unsigned int PQ::ModifyCommand::execute(bool anc) { - PGresult * res = PQexecPrepared(c->conn, prepare()->second.c_str(), values.size(), &values.front(), &lengths.front(), NULL, 0); + PGresult * res = PQexecPrepared(c->conn, pstmt.c_str(), values.size(), &values.front(), &lengths.front(), NULL, 0); c->checkResult(res, PGRES_COMMAND_OK, PGRES_TUPLES_OK); unsigned int rows = atoi(PQcmdTuples(res)); PQclear(res); -- cgit v1.2.3