diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-26 20:47:35 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-26 20:47:35 +0000 |
commit | 203936297e449f0215641037736cc4d142fd4a60 (patch) | |
tree | e2b8ea54713c563cb545a91f791e929b3e19a704 /libpqpp/pq-modifycommand.cpp | |
parent | Reuse prepared statements (diff) | |
download | libdbpp-postgresql-203936297e449f0215641037736cc4d142fd4a60.tar.bz2 libdbpp-postgresql-203936297e449f0215641037736cc4d142fd4a60.tar.xz libdbpp-postgresql-203936297e449f0215641037736cc4d142fd4a60.zip |
Prepare statement upfront during construction
Diffstat (limited to 'libpqpp/pq-modifycommand.cpp')
-rw-r--r-- | libpqpp/pq-modifycommand.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
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<std::string>()(sql)) + pstmt(prepare()->second) { } @@ -18,6 +18,7 @@ PQ::ModifyCommand::~ModifyCommand() PQ::Connection::PreparedStatements::const_iterator PQ::ModifyCommand::prepare() const { + auto hash(std::hash<std::string>()(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); |