Herunterladen als
root/src/query.h @ 7f1090e5
38838b5b | Christian Ehringfeld | /*
|
|
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
|||
*
|
|||
* This program is free software; you can redistribute it and/or modify it
|
|||
* under the terms of the GNU Lesser General Public License as published by
|
|||
* the Free Software Foundation.
|
|||
*
|
|||
* This program is distributed in the hope that it will be useful, but
|
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|||
* for more details.
|
|||
*
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
|||
5d93390e | Christian Ehringfeld | #ifndef QUERY_H
|
|
#define QUERY_H
|
|||
#include <QString>
|
|||
#include <QHash>
|
|||
#include <QVariant>
|
|||
#include <QLinkedList>
|
|||
#include "join.h"
|
|||
3160499c | Christian Ehringfeld | #include "expression.h"
|
|
ae331910 | Christian Ehringfeld | #include "orderby.h"
|
|
5d93390e | Christian Ehringfeld | namespace CuteEntityManager {
|
|
2ee5022f | Christian Ehringfeld | class Condition;
|
|
3160499c | Christian Ehringfeld | class OrderBy;
|
|
358e1e04 | Christian Ehringfeld | class QueryBuilder;
|
|
class Entity;
|
|||
/**
|
|||
* @brief The JokerPosition enum
|
|||
* FRONT -> e.g. "%foo"
|
|||
* BEHIND -> e.g. "foo%"
|
|||
* BOTH -> e.g. "%foo%"
|
|||
*/
|
|||
enum class JokerPosition {
|
|||
FRONT,
|
|||
BEHIND,
|
|||
BOTH,
|
|||
NONE
|
|||
};
|
|||
3160499c | Christian Ehringfeld | enum class Direction;
|
|
2ee5022f | Christian Ehringfeld | class Query {
|
|
public:
|
|||
5d93390e | Christian Ehringfeld | Query();
|
|
dbd41a3a | Christian Ehringfeld | virtual ~Query();
|
|
28d2f01a | Christian Ehringfeld | explicit Query(QStringList from, QList<Expression> where = QList<Expression>(),
|
|
QList<Join> joins = QList<Join>(),
|
|||
QHash<QString, QVariant> params = QHash<QString, QVariant>(), quint64 limit = 0,
|
|||
quint64 offset = 0,
|
|||
QList<Expression> select = QList<Expression>(),
|
|||
QStringList groupBy = QStringList(), bool distinct = false,
|
|||
QList<Expression> having = QList<Expression>());
|
|||
explicit Query(QString from, Expression where = Expression(),
|
|||
Join join = Join(),
|
|||
QHash<QString, QVariant> params = QHash<QString, QVariant>(), quint64 limit = 0,
|
|||
quint64 offset = 0,
|
|||
Expression select = Expression(),
|
|||
QString groupBy = "", bool distinct = false,
|
|||
QList<Expression> having = QList<Expression>());
|
|||
5d93390e | Christian Ehringfeld | ||
QString getSelectOption() const;
|
|||
void setSelectOption(const QString &value);
|
|||
bool getDistinct() const;
|
|||
void setDistinct(bool value);
|
|||
82442988 | Christian Ehringfeld | void appendFrom(const QString &value);
|
|
5d93390e | Christian Ehringfeld | QStringList getFrom() const;
|
|
void setFrom(const QStringList &value);
|
|||
e3fc2748 | Christian Ehringfeld | void appendJoinWith(const QString value);
|
|
82442988 | Christian Ehringfeld | void appendJoin(const Join &value);
|
|
c9f21778 | Christian Ehringfeld | void appendJoins(const QList<Join> &value);
|
|
5d93390e | Christian Ehringfeld | QList<Join> getJoins() const;
|
|
void setJoins(const QList<Join> &value);
|
|||
void appendParam(const QString &column, QVariant value);
|
|||
506067a2 | Christian Ehringfeld | void appendParams(const QHash<QString, QVariant> ¶ms);
|
|
5d93390e | Christian Ehringfeld | QHash<QString, QVariant> getParams() const;
|
|
void setParams(const QHash<QString, QVariant> &value);
|
|||
506067a2 | Christian Ehringfeld | quint64 getLimit() const;
|
|
void setLimit(const quint64 &value);
|
|||
5d93390e | Christian Ehringfeld | ||
506067a2 | Christian Ehringfeld | quint64 getOffset() const;
|
|
void setOffset(const quint64 &value);
|
|||
5d93390e | Christian Ehringfeld | ||
3160499c | Christian Ehringfeld | void appendOrderBy(const OrderBy &orderBy);
|
|
void appendOrderBy(const QString &column, const Direction &direction);
|
|||
QList<OrderBy> getOrderBy() const;
|
|||
void setOrderBy(const QList<OrderBy> &value);
|
|||
82442988 | Christian Ehringfeld | void appendGroupBy(const QString &value);
|
|
3160499c | Christian Ehringfeld | QStringList getGroupBy() const;
|
|
void setGroupBy(const QStringList &value);
|
|||
QList<Expression> getSelect() const;
|
|||
void appendSelect(const Expression &value);
|
|||
void appendSelect(const QString &value);
|
|||
void setSelect(const QList<Expression> &value);
|
|||
void setSelect(const QStringList &value);
|
|||
5d93390e | Christian Ehringfeld | ||
82442988 | Christian Ehringfeld | void appendWhere(const QString &condition);
|
|
void appendWhere(const Expression &condition);
|
|||
506067a2 | Christian Ehringfeld | QList<Expression> getWhere() const;
|
|
void setWhere(const QList<Expression> &value);
|
|||
82442988 | Christian Ehringfeld | void appendHaving(const QString &condition);
|
|
void appendHaving(const Expression &condition);
|
|||
506067a2 | Christian Ehringfeld | QList<Expression> getHaving() const;
|
|
void setHaving(const QList<Expression> &value);
|
|||
358e1e04 | Christian Ehringfeld | ||
Expression whereCondition(const QSharedPointer<QueryBuilder> &qb, QString column, QVariant value) const;
|
|||
Join joinClasses(const QSharedPointer<QueryBuilder> &qb,
|
|||
const QSharedPointer<Entity> &mainEntity,
|
|||
const QSharedPointer<Entity> &foreignEntity,
|
|||
const QString &joinType = QStringLiteral("LEFT JOIN"))const;
|
|||
QList<Join> joinBaseClasses(const QSharedPointer<QueryBuilder> &qb,
|
|||
const QSharedPointer<Entity> &entity);
|
|||
Expression whereCondition(const QSharedPointer<QueryBuilder> &qb,
|
|||
QHash<QString, QVariant> conditions,
|
|||
QString conjunction = QStringLiteral("AND")) const;
|
|||
Expression whereCondition(const QSharedPointer<QueryBuilder> &qb, QString condition,
|
|||
QHash<QString, QVariant> values = QHash<QString, QVariant>()) const;
|
|||
01fe6db3 | Christian Ehringfeld | Expression equal(const QSharedPointer<QueryBuilder> &qb, QString key, QVariant value) const;
|
|
Expression notEqual(const QSharedPointer<QueryBuilder> &qb, QString key,
|
|||
QVariant value) const;
|
|||
358e1e04 | Christian Ehringfeld | Expression between(const QSharedPointer<QueryBuilder> &qb, QString column,
|
|
QVariant firstValue,
|
|||
QVariant secondValue) const;
|
|||
Expression notBetween(const QSharedPointer<QueryBuilder> &qb, QString column,
|
|||
QVariant firstValue,
|
|||
QVariant secondValue) const;
|
|||
Expression in(const QSharedPointer<QueryBuilder> &qb, QString column,
|
|||
QList<QVariant> values) const;
|
|||
Expression notIn(const QSharedPointer<QueryBuilder> &qb, QString column,
|
|||
QList<QVariant> values) const;
|
|||
Expression notOperator(const QSharedPointer<QueryBuilder> &qb, QString op, QString column,
|
|||
QVariant value) const;
|
|||
Expression orOperator(const QSharedPointer<QueryBuilder> &qb,
|
|||
QHash<QString, QVariant> conditions,
|
|||
bool like = false) const;
|
|||
Expression orOperator(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression norOperator(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression andOperator(const QSharedPointer<QueryBuilder> &qb,
|
|||
QHash<QString, QVariant> conditions) const;
|
|||
Expression andOperator(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression nandOperator(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression arbitraryOperator(const QSharedPointer<QueryBuilder> &qb, QString op,
|
|||
QString column,
|
|||
QVariant value) const;
|
|||
Expression isNull(const QSharedPointer<QueryBuilder> &qb, QString column) const;
|
|||
Expression isNotNull(const QSharedPointer<QueryBuilder> &qb, QString column) const;
|
|||
Expression plainOr(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression plainNor(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression plainAnd(const QSharedPointer<QueryBuilder> &qb)
|
|||
const;
|
|||
Expression plainNand(const QSharedPointer<QueryBuilder> &qb) const;
|
|||
Expression like(const QSharedPointer<QueryBuilder> &qb, QString column, QVariant value,
|
|||
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
|
|||
Expression like(const QSharedPointer<QueryBuilder> &qb,
|
|||
QHash<QString, QVariant> conditions,
|
|||
QString conjunction = QStringLiteral("AND"),
|
|||
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
|
|||
38838b5b | Christian Ehringfeld | private:
|
|
3160499c | Christian Ehringfeld | QList<Expression> select;
|
|
5d93390e | Christian Ehringfeld | QString selectOption = QStringLiteral("");
|
|
bool distinct = false;
|
|||
QStringList from;
|
|||
QStringList groupBy;
|
|||
3160499c | Christian Ehringfeld | QList<OrderBy> orderBy;
|
|
506067a2 | Christian Ehringfeld | QList<Expression> where;
|
|
QList<Expression> having;
|
|||
5d93390e | Christian Ehringfeld | QList<Join> joins;
|
|
QHash<QString, QVariant> params;
|
|||
506067a2 | Christian Ehringfeld | quint64 limit = 0;
|
|
quint64 offset = 0;
|
|||
5d93390e | Christian Ehringfeld | };
|
|
}
|
|||
#endif // QUERY_H
|