From 19d7c80017b560645f8ad3fefeef6f11e410ecf4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Jan 2017 19:34:49 +0000 Subject: Add sql source wrappers to get commands with options containing hash and any given options --- icetray/icetray/abstractDatabaseClient.h | 2 +- icetray/icetray/sqlSource.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/icetray/icetray/abstractDatabaseClient.h b/icetray/icetray/abstractDatabaseClient.h index 50a7cda..4c65ff7 100644 --- a/icetray/icetray/abstractDatabaseClient.h +++ b/icetray/icetray/abstractDatabaseClient.h @@ -18,7 +18,7 @@ namespace IceTray { fetch(const SqlSource & sql, const Params & ... params) { auto c = db->get(); - auto s = c->select(sql.getSql()); + auto s = sql.select(c.get()); bind(0, s.get(), params...); return Slicer::DeserializeAny(*s); } diff --git a/icetray/icetray/sqlSource.h b/icetray/icetray/sqlSource.h index 25ed933..a0e8ea1 100644 --- a/icetray/icetray/sqlSource.h +++ b/icetray/icetray/sqlSource.h @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include namespace IceTray { class DLL_PUBLIC SqlSource { @@ -12,6 +15,20 @@ namespace IceTray { virtual const std::string & getSql() const = 0; virtual std::size_t getSqlHash() const; + + template + DB::ModifyCommandPtr modify(DB::Connection * db, const Opts & ... opts) const + { + OptsType o(getSqlHash(), opts...); + return db->modify(getSql(), &o); + } + + template + DB::SelectCommandPtr select(DB::Connection * db, const Opts & ... opts) const + { + OptsType o(getSqlHash(), opts...); + return db->select(getSql(), &o); + } }; } -- cgit v1.2.3