summaryrefslogtreecommitdiff
path: root/libpqpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-01-01 20:08:22 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-01-01 20:08:22 +0000
commitdaaf7b3facc18bc3073b0ffb245e1c86d8670b8b (patch)
tree3bf72e869b9e19098bdf5792654a02daa230b207 /libpqpp
parentAPI change to pass command options through (diff)
downloadlibdbpp-postgresql-daaf7b3facc18bc3073b0ffb245e1c86d8670b8b.tar.bz2
libdbpp-postgresql-daaf7b3facc18bc3073b0ffb245e1c86d8670b8b.tar.xz
libdbpp-postgresql-daaf7b3facc18bc3073b0ffb245e1c86d8670b8b.zip
Use command options statement hash when it's availablelibdbpp-postgresql-1.1.0
Diffstat (limited to 'libpqpp')
-rw-r--r--libpqpp/pq-bulkselectcommand.cpp4
-rw-r--r--libpqpp/pq-bulkselectcommand.h2
-rw-r--r--libpqpp/pq-connection.cpp8
-rw-r--r--libpqpp/pq-modifycommand.cpp4
-rw-r--r--libpqpp/pq-modifycommand.h2
-rw-r--r--libpqpp/pq-prepared.cpp4
-rw-r--r--libpqpp/pq-prepared.h4
7 files changed, 15 insertions, 13 deletions
diff --git a/libpqpp/pq-bulkselectcommand.cpp b/libpqpp/pq-bulkselectcommand.cpp
index 8b669f4..466eaaf 100644
--- a/libpqpp/pq-bulkselectcommand.cpp
+++ b/libpqpp/pq-bulkselectcommand.cpp
@@ -3,10 +3,10 @@
#include "pq-column.h"
#include "pq-error.h"
-PQ::BulkSelectCommand::BulkSelectCommand(Connection * conn, const std::string & sql, unsigned int no) :
+PQ::BulkSelectCommand::BulkSelectCommand(Connection * conn, const std::string & sql, unsigned int no, const DB::CommandOptions * opts) :
DB::Command(sql),
DB::SelectCommand(sql),
- PQ::PreparedStatement(conn, sql, no),
+ PQ::PreparedStatement(conn, sql, no, opts),
executed(false)
{
}
diff --git a/libpqpp/pq-bulkselectcommand.h b/libpqpp/pq-bulkselectcommand.h
index 58b01aa..e4775d4 100644
--- a/libpqpp/pq-bulkselectcommand.h
+++ b/libpqpp/pq-bulkselectcommand.h
@@ -12,7 +12,7 @@ namespace PQ {
class Column;
class BulkSelectCommand : public DB::SelectCommand, public SelectBase, public PreparedStatement {
public:
- BulkSelectCommand(Connection *, const std::string & sql, unsigned int no);
+ BulkSelectCommand(Connection *, const std::string & sql, unsigned int no, const DB::CommandOptions *);
virtual ~BulkSelectCommand();
bool fetch() override;
diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp
index ec53981..590435e 100644
--- a/libpqpp/pq-connection.cpp
+++ b/libpqpp/pq-connection.cpp
@@ -97,19 +97,19 @@ PQ::Connection::ping() const
DB::SelectCommand *
-PQ::Connection::newSelectCommand(const std::string & sql, const DB::CommandOptions *)
+PQ::Connection::newSelectCommand(const std::string & sql, const DB::CommandOptions * opts)
{
// Yes, this is a hack
if (sql.find("libdbpp:no-cursor") != (std::string::size_type)-1) {
- return new BulkSelectCommand(this, sql, pstmntNo++);
+ return new BulkSelectCommand(this, sql, pstmntNo++, opts);
}
return new CursorSelectCommand(this, sql, pstmntNo++);
}
DB::ModifyCommand *
-PQ::Connection::newModifyCommand(const std::string & sql, const DB::CommandOptions *)
+PQ::Connection::newModifyCommand(const std::string & sql, const DB::CommandOptions * opts)
{
- return new ModifyCommand(this, sql, pstmntNo++);
+ return new ModifyCommand(this, sql, pstmntNo++, opts);
}
bool
diff --git a/libpqpp/pq-modifycommand.cpp b/libpqpp/pq-modifycommand.cpp
index 4cc31d2..f8e4d63 100644
--- a/libpqpp/pq-modifycommand.cpp
+++ b/libpqpp/pq-modifycommand.cpp
@@ -3,10 +3,10 @@
#include <stdlib.h>
#include "pq-connection.h"
-PQ::ModifyCommand::ModifyCommand(Connection * conn, const std::string & sql, unsigned int no) :
+PQ::ModifyCommand::ModifyCommand(Connection * conn, const std::string & sql, unsigned int no, const DB::CommandOptions * opts) :
DB::Command(sql),
DB::ModifyCommand(sql),
- PQ::PreparedStatement(conn, sql, no)
+ PQ::PreparedStatement(conn, sql, no, opts)
{
}
diff --git a/libpqpp/pq-modifycommand.h b/libpqpp/pq-modifycommand.h
index ef50261..4f0a481 100644
--- a/libpqpp/pq-modifycommand.h
+++ b/libpqpp/pq-modifycommand.h
@@ -8,7 +8,7 @@
namespace PQ {
class ModifyCommand : public DB::ModifyCommand, public PreparedStatement {
public:
- ModifyCommand(Connection *, const std::string & sql, unsigned int no);
+ ModifyCommand(Connection *, const std::string & sql, unsigned int no, const DB::CommandOptions *);
virtual ~ModifyCommand();
unsigned int execute(bool) override;
diff --git a/libpqpp/pq-prepared.cpp b/libpqpp/pq-prepared.cpp
index 4cd4540..bdf2a7d 100644
--- a/libpqpp/pq-prepared.cpp
+++ b/libpqpp/pq-prepared.cpp
@@ -1,9 +1,10 @@
#include "pq-prepared.h"
#include "pq-connection.h"
-PQ::PreparedStatement::PreparedStatement(Connection * c, const std::string & sql, unsigned int no) :
+PQ::PreparedStatement::PreparedStatement(Connection * c, const std::string & sql, unsigned int no, const DB::CommandOptions * opts) :
DB::Command(sql),
Command(c, sql, no),
+ hash(opts && opts->hash ? *opts->hash : std::hash<std::string>()(sql)),
pstmt(nullptr)
{
}
@@ -14,7 +15,6 @@ PQ::PreparedStatement::prepare() const
if (pstmt) {
return pstmt;
}
- auto hash(std::hash<std::string>()(sql));
auto i = c->preparedStatements.find(hash);
if (i != c->preparedStatements.end()) {
return (pstmt = i->second.c_str());
diff --git a/libpqpp/pq-prepared.h b/libpqpp/pq-prepared.h
index 1f6e028..0f745c9 100644
--- a/libpqpp/pq-prepared.h
+++ b/libpqpp/pq-prepared.h
@@ -2,14 +2,16 @@
#define stuff
#include "pq-command.h"
+#include "pq-connection.h"
namespace PQ {
class PreparedStatement : public Command {
protected:
- PreparedStatement(Connection *, const std::string &, unsigned int);
+ PreparedStatement(Connection *, const std::string &, unsigned int, const DB::CommandOptions *);
virtual ~PreparedStatement() = default;
const char * prepare() const;
+ Connection::StatementHash hash;
mutable const char * pstmt;
};
}