diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-24 22:09:25 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-24 22:09:25 +0100 |
commit | a10dde58066098f9fcfd87e2487a16c8d25cb4da (patch) | |
tree | 794591347832e9067d7b717a390bd776efcf32c7 | |
parent | Add count tests for deps (diff) | |
download | gentoobrowse-api-a10dde58066098f9fcfd87e2487a16c8d25cb4da.tar.bz2 gentoobrowse-api-a10dde58066098f9fcfd87e2487a16c8d25cb4da.tar.xz gentoobrowse-api-a10dde58066098f9fcfd87e2487a16c8d25cb4da.zip |
Extend EntityWhereFilter to operate on a set of Ids
-rw-r--r-- | gentoobrowse-api/service/utils/entityWhereFilter.cpp | 28 | ||||
-rw-r--r-- | gentoobrowse-api/service/utils/entityWhereFilter.h | 7 |
2 files changed, 31 insertions, 4 deletions
diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.cpp b/gentoobrowse-api/service/utils/entityWhereFilter.cpp index d6189bd..be80971 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.cpp +++ b/gentoobrowse-api/service/utils/entityWhereFilter.cpp @@ -3,8 +3,19 @@ namespace Gentoo { namespace Utils { + EntityWhereFilter::EntityWhereFilter(const std::string & en) : + entityColName(en) + { + } + EntityWhereFilter::EntityWhereFilter(const std::string & en, int64_t e) : - entityId(e), + entityColName(en) + { + entityIds.insert(e); + } + + EntityWhereFilter::EntityWhereFilter(const std::string & en, const EntityIds & e) : + entityIds(e), entityColName(en) { } @@ -12,13 +23,24 @@ namespace Gentoo { void EntityWhereFilter::writeSql(AdHoc::Buffer & sql) { - sql.appendbf("a.%s = ?", entityColName); + sql.appendbf("a.%s IN (", entityColName); + for (EntityIds::const_iterator ei = entityIds.begin(); ei != entityIds.end(); ++ei) { + if (ei != entityIds.begin()) { + sql.append(", ?"); + } + else { + sql.append("?"); + } + } + sql.append(")"); } void EntityWhereFilter::bindParams(DB::Command * c, unsigned int & offset) { - c->bindParamI(offset++, entityId); + for (const auto & entityId : entityIds) { + c->bindParamI(offset++, entityId); + } } } } diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.h b/gentoobrowse-api/service/utils/entityWhereFilter.h index 20420c3..a637288 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.h +++ b/gentoobrowse-api/service/utils/entityWhereFilter.h @@ -2,17 +2,22 @@ #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H #include <sqlWriter.h> +#include <set> namespace Gentoo { namespace Utils { class EntityWhereFilter : public DB::SqlWriter { public: + typedef std::set<int64_t> EntityIds; + + EntityWhereFilter(const std::string & en); EntityWhereFilter(const std::string & en, int64_t e); + EntityWhereFilter(const std::string & en, const EntityIds & e); void writeSql(AdHoc::Buffer & sql) override; void bindParams(DB::Command * c, unsigned int & offset) override; - const int64_t entityId; + EntityIds entityIds; const std::string entityColName; }; } |