summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.cpp28
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.h7
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;
};
}