Commit 950c2717 authored by Konrad Czapla's avatar Konrad Czapla
Browse files

Limit support for FETCH command - Remove concatenating column names

parent c8f22a7f
......@@ -107,15 +107,15 @@ QSqlQuery ItemFetchHelper::buildPartQuery(const QVector<QByteArray> &partList, b
}
if (!partList.isEmpty() || allPayload || allAttrs) {
partQuery.addJoin(QueryBuilder::InnerJoin, Part::tableName(), partQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), Part::pimItemIdFullColumnName());
partQuery.addColumn(partQuery.getTable() + QLatin1Char('.') + PimItem::idColumn());
partQuery.addJoin(QueryBuilder::InnerJoin, Part::tableName(), partQuery.getTableWithColumn(PimItem::idColumn()), Part::pimItemIdFullColumnName());
partQuery.addColumn(partQuery.getTableWithColumn(PimItem::idColumn()));
partQuery.addColumn(Part::partTypeIdFullColumnName());
partQuery.addColumn(Part::dataFullColumnName());
partQuery.addColumn(Part::storageFullColumnName());
partQuery.addColumn(Part::versionFullColumnName());
partQuery.addColumn(Part::datasizeFullColumnName());
partQuery.addSortColumn(partQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), Query::Descending);
partQuery.addSortColumn(partQuery.getTableWithColumn(PimItem::idColumn()), Query::Descending);
if (!partList.isEmpty() || allPayload || allAttrs) {
Query::Condition cond(Query::Or);
......@@ -209,13 +209,13 @@ QSqlQuery ItemFetchHelper::buildFlagQuery()
flagQuery = QueryBuilder(mItemQuery.query(), mPimItemQueryAlias);
}
flagQuery.addJoin(QueryBuilder::InnerJoin, PimItemFlagRelation::tableName(), flagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemFlagRelation::leftFullColumnName());
flagQuery.addJoin(QueryBuilder::InnerJoin, PimItemFlagRelation::tableName(), flagQuery.getTableWithColumn(PimItem::idColumn()), PimItemFlagRelation::leftFullColumnName());
flagQuery.addColumn(flagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn());
flagQuery.addColumn(flagQuery.getTableWithColumn(PimItem::idColumn()));
flagQuery.addColumn(PimItemFlagRelation::rightFullColumnName());
ItemQueryHelper::scopeToQuery(mScope, mContext, flagQuery);
flagQuery.addSortColumn(flagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), Query::Descending);
flagQuery.addSortColumn(flagQuery.getTableWithColumn(PimItem::idColumn()), Query::Descending);
if (!flagQuery.exec()) {
throw HandlerException("Unable to retrieve item flags");
......@@ -238,13 +238,13 @@ QSqlQuery ItemFetchHelper::buildTagQuery()
tagQuery = QueryBuilder(mItemQuery.query(), mPimItemQueryAlias);
}
tagQuery.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), tagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
tagQuery.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), tagQuery.getTableWithColumn(PimItem::idColumn()), PimItemTagRelation::leftFullColumnName());
tagQuery.addJoin(QueryBuilder::InnerJoin, Tag::tableName(), Tag::idFullColumnName(), PimItemTagRelation::rightFullColumnName());
tagQuery.addColumn(tagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn());
tagQuery.addColumn(tagQuery.getTableWithColumn(PimItem::idColumn()));
tagQuery.addColumn(Tag::idFullColumnName());
ItemQueryHelper::scopeToQuery(mScope, mContext, tagQuery);
tagQuery.addSortColumn(tagQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), Query::Descending);
tagQuery.addSortColumn(tagQuery.getTableWithColumn(PimItem::idColumn()), Query::Descending);
if (!tagQuery.exec()) {
throw HandlerException("Unable to retrieve item tags");
......@@ -270,11 +270,11 @@ QSqlQuery ItemFetchHelper::buildVRefQuery()
vRefQuery.addJoin(QueryBuilder::LeftJoin,
CollectionPimItemRelation::tableName(),
CollectionPimItemRelation::rightFullColumnName(),
vRefQuery.getTable() + QLatin1Char('.') + PimItem::idColumn());
vRefQuery.getTableWithColumn(PimItem::idColumn()));
vRefQuery.addColumn(CollectionPimItemRelation::leftFullColumnName());
vRefQuery.addColumn(CollectionPimItemRelation::rightFullColumnName());
ItemQueryHelper::scopeToQuery(mScope, mContext, vRefQuery);
vRefQuery.addSortColumn(vRefQuery.getTable() + QLatin1Char('.') + PimItem::idColumn(), Query::Descending);
vRefQuery.addSortColumn(vRefQuery.getTableWithColumn(PimItem::idColumn()), Query::Descending);
if (!vRefQuery.exec()) {
throw HandlerException("Unable to retrieve virtual references");
......
......@@ -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, qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), qb);
QueryHelper::setToQuery(set, qb.getTableWithColumn(PimItem::idColumn()), qb);
}
if (collection.isValid()) {
if (collection.isVirtual() || collection.resource().isVirtual()) {
qb.addJoin(QueryBuilder::InnerJoin,
CollectionPimItemRelation::tableName(),
CollectionPimItemRelation::rightFullColumnName(),
qb.getTable() + QLatin1Char('.') + PimItem::idColumn());
qb.getTableWithColumn(PimItem::idColumn()));
qb.addValueCondition(CollectionPimItemRelation::leftFullColumnName(), Query::Equals, collection.id());
} else {
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Query::Equals, collection.id());
qb.addValueCondition(qb.getTableWithColumn(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(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTableWithColumn(PimItem::collectionIdColumn()), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTableWithColumn(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(qb.getTable() + QLatin1Char('.') + PimItem::remoteIdColumn(), Query::Equals, rids.first());
qb.addValueCondition(qb.getTableWithColumn(PimItem::remoteIdColumn()), Query::Equals, rids.first());
} else {
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::remoteIdColumn(), Query::In, rids);
qb.addValueCondition(qb.getTableWithColumn(PimItem::remoteIdColumn()), Query::In, rids);
}
if (context.resource().isValid()) {
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTableWithColumn(PimItem::collectionIdColumn()), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
if (context.collectionId() > 0) {
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Query::Equals, context.collectionId());
qb.addValueCondition(qb.getTableWithColumn(PimItem::collectionIdColumn()), Query::Equals, context.collectionId());
}
const auto tagId = context.tagId();
if (tagId.has_value()) {
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTableWithColumn(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(qb.getTable() + QLatin1Char('.') + PimItem::gidColumn(), Query::Equals, gids.first());
qb.addValueCondition(qb.getTableWithColumn(PimItem::gidColumn()), Query::Equals, gids.first());
} else {
qb.addValueCondition(qb.getTable() + QLatin1Char('.') + PimItem::gidColumn(), Query::In, gids);
qb.addValueCondition(qb.getTableWithColumn(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(), qb.getTable() + QLatin1Char('.') + PimItem::collectionIdColumn(), Collection::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), qb.getTableWithColumn(PimItem::collectionIdColumn()), Collection::idFullColumnName());
qb.addValueCondition(Collection::resourceIdFullColumnName(), Query::Equals, context.resource().id());
}
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTable() + QLatin1Char('.') + PimItem::idColumn(), PimItemTagRelation::leftFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, PimItemTagRelation::tableName(), qb.getTableWithColumn(PimItem::idColumn()), PimItemTagRelation::leftFullColumnName());
qb.addValueCondition(PimItemTagRelation::rightFullColumnName(), Query::Equals, *tagId);
}
}
......
Supports Markdown
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