Commit 25039495 authored by Konrad Czapla's avatar Konrad Czapla
Browse files

Use table names for items from QueryBuilder

parent 55d4c729
......@@ -21,17 +21,17 @@ using namespace Akonadi::Server;
void ItemQueryHelper::itemSetToQuery(const ImapSet &set, QueryBuilder &qb, const Collection &collection)
{
if (!set.isEmpty()) {
QueryHelper::setToQuery(set, PimItem::idFullColumnName(), qb);
QueryHelper::setToQuery(set, qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), qb);
}
if (collection.isValid()) {
if (collection.isVirtual() || collection.resource().isVirtual()) {
qb.addJoin(QueryBuilder::InnerJoin,
CollectionPimItemRelation::tableName(),
CollectionPimItemRelation::rightFullColumnName(),
PimItem::idFullColumnName());
qb.getTable() + QLatin1Char('.') + PimItem::idColumn());
qb.addValueCondition(CollectionPimItemRelation::leftFullColumnName(), Query::Equals, collection.id());
} else {
qb.addValueCondition(PimItem::collectionIdFullColumnName(), Query::Equals, collection.id());
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Query::Equals, collection.id());
}
}
}
......@@ -48,10 +48,10 @@ void ItemQueryHelper::itemSetToQuery(const ImapSet &set, const CommandContext &c
if (tagId.has_value()) {
// When querying for items by tag, only return matches from that resource
if (context.resource().isValid()) {
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), PimItem::collectionIdFullColumnName(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), PimItem::idFullColumnName(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addValueCondition(PimItemTagRelation::rightFullColumnName(), Query::Equals, *tagId);
}
}
......@@ -59,22 +59,22 @@ void ItemQueryHelper::itemSetToQuery(const ImapSet &set, const CommandContext &c
void ItemQueryHelper::remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
{
if (rids.size() == 1) {
qb.addValueCondition(PimItem::remoteIdFullColumnName(), Query::Equals, rids.first());
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::remoteIdColumn(), Query::Equals, rids.first());
} else {
qb.addValueCondition(PimItem::remoteIdFullColumnName(), Query::In, rids);
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::remoteIdColumn(), Query::In, rids);
}
if (context.resource().isValid()) {
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), PimItem::collectionIdFullColumnName(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
if (context.collectionId() > 0) {
qb.addValueCondition(PimItem::collectionIdFullColumnName(), Query::Equals, context.collectionId());
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Query::Equals, context.collectionId());
}
const auto tagId = context.tagId();
if (tagId.has_value()) {
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), PimItem::idFullColumnName(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addValueCondition(PimItemTagRelation::rightFullColumnName(), Query::Equals, *tagId);
}
}
......@@ -82,19 +82,19 @@ void ItemQueryHelper::remoteIdToQuery(const QStringList &rids, const CommandCont
void ItemQueryHelper::gidToQuery(const QStringList &gids, const CommandContext &context, QueryBuilder &qb)
{
if (gids.size() == 1) {
qb.addValueCondition(PimItem::gidFullColumnName(), Query::Equals, gids.first());
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::gidColumn(), Query::Equals, gids.first());
} else {
qb.addValueCondition(PimItem::gidFullColumnName(), Query::In, gids);
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::gidColumn(), Query::In, gids);
}
const auto tagId = context.tagId();
if (tagId.has_value()) {
// When querying for items by tag, only return matches from that resource
if (context.resource().isValid()) {
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), PimItem::collectionIdFullColumnName(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), PimItem::idFullColumnName(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addValueCondition(PimItemTagRelation::rightFullColumnName(), Query::Equals, *tagId);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment