Collection HandlerHelper::collectionFromIdOrName(const QByteArray &id) { // id is a number bool ok = false; qint64 collectionId = id.toLongLong(&ok); if (ok) { return Collection::retrieveById(collectionId); } // id is a path QString path = QString::fromUtf8(id); // ### should be UTF-7 for real IMAP compatibility const QStringList pathParts = path.split(QLatin1Char('/'), QString::SkipEmptyParts); Collection col; for (const QString &part : pathParts) { SelectQueryBuilder<Collection> qb; qb.addValueCondition(Collection::nameColumn(), Query::Equals, part); if (col.isValid()) { qb.addValueCondition(Collection::parentIdColumn(), Query::Equals, col.id()); } else { qb.addValueCondition(Collection::parentIdColumn(), Query::Is, QVariant()); } if (!qb.exec()) { return Collection(); } Collection::List list = qb.result(); if (list.count() != 1) { return Collection(); } col = list.first(); } return col; }
bool RelationFetch::parseStream() { Protocol::FetchRelationsCommand cmd(m_command); SelectQueryBuilder<Relation> relationQuery; if (cmd.side() > 0) { Query::Condition c; c.setSubQueryMode(Query::Or); c.addValueCondition(Relation::leftIdFullColumnName(), Query::Equals, cmd.side()); c.addValueCondition(Relation::rightIdFullColumnName(), Query::Equals, cmd.side()); relationQuery.addCondition(c); } else { if (cmd.left() > 0) { relationQuery.addValueCondition(Relation::leftIdFullColumnName(), Query::Equals, cmd.left()); } if (cmd.right() > 0) { relationQuery.addValueCondition(Relation::rightIdFullColumnName(), Query::Equals, cmd.right()); } } if (!cmd.types().isEmpty()) { relationQuery.addJoin(QueryBuilder::InnerJoin, RelationType::tableName(), Relation::typeIdFullColumnName(), RelationType::idFullColumnName()); QStringList types; types.reserve(cmd.types().size()); Q_FOREACH (const QByteArray &type, cmd.types()) { types << QString::fromUtf8(type); } relationQuery.addValueCondition(RelationType::nameFullColumnName(), Query::In, types); }