Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 274b34e4

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 274b34e43dfa8854fe060de5820a3214912b5ff6
  • Vorgänger e2ee17bf
  • Nachfolger 5baea70c

constness

Unterschiede anzeigen:

samples/example/main.cpp
qWarning() << "-----------------------------";
Query q = Query();
q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim")));
q.appendJoin(Join("person", "pupil.id = person.id"));
q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
JokerPosition::BEHIND));
q.appendWhere(e->getQueryBuilder()->andOperator());
q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
QDate(2000, 10, 10)));
//q.appendJoin(Join("person", "pupil.id = person.id"));
q.setDistinct(true);
q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
q.setLimit(10);
QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q);
QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q, true);
for (int i = 0; i < list.size(); ++i) {
qWarning() << list.at(i)->toString();
}
src/querybuilder.cpp
}
Expression QueryBuilder::inFunction(QString column,
QList<QVariant> values, bool notOp) {
QList<QVariant> values, bool notOp) const {
QString condition = "";
Expression exp = Expression();
if (!values.isEmpty()) {
......
}
QString QueryBuilder::between(QString colName, QString valName1,
QString valName2, bool notOp) {
QString valName2, bool notOp) const {
return "(" + this->schema->quoteColumnName(colName) + (notOp ? (" " +
this->notKeyword() + " ") : " ") + this->between() +
" " + this->placeHolder(valName1) + " " + this->andKeyword() + " " +
......
return "OFFSET";
}
QString QueryBuilder::appendNot(bool notOp) {
QString QueryBuilder::appendNot(bool notOp) const {
return (notOp ? (this->notKeyword() + " ") : "");
}
......
pk = value;
}
Expression QueryBuilder::andOperator(QHash<QString, QVariant> conditions) {
Expression QueryBuilder::andOperator(QHash<QString, QVariant> conditions)
const {
bool first = true;
Expression exp = Expression();
QString condition = "";
......
return exp;
}
Expression QueryBuilder::andOperator() const {
return this->plainAnd();
}
Expression QueryBuilder::nandOperator() const {
return this->plainNand();
}
Expression QueryBuilder::arbitraryOperator(QString op, QString column,
QVariant value) {
QVariant value) const {
Expression exp = Expression(this->schema->quoteColumnName(
column) + " " + op + " " +
this->placeHolder(column));
......
return exp;
}
Expression QueryBuilder::isNull(QString column) {
Expression QueryBuilder::isNull(QString column) const {
return Expression(this->schema->quoteColumnName(column) + " IS NULL");
}
Expression QueryBuilder::isNotNull(QString column) {
Expression QueryBuilder::isNotNull(QString column) const {
return Expression(this->schema->quoteColumnName(column) + " IS " +
this->notKeyword() + " NULL");
}
Expression QueryBuilder::plainOr() {
Expression QueryBuilder::plainOr() const {
return Expression(this->orKeyword());
}
Expression QueryBuilder::plainNor() {
Expression QueryBuilder::plainNor() const {
return Expression(this->notKeyword() + " " + this->orKeyword());
}
Expression QueryBuilder::plainAnd() {
Expression QueryBuilder::plainAnd() const {
return Expression(this->andKeyword());
}
Expression QueryBuilder::plainNand() {
Expression QueryBuilder::plainNand() const {
return Expression(this->notKeyword() + " " + this->andKeyword());
}
......
}
Expression QueryBuilder::where(QHash<QString, QVariant> conditions,
QString conjunction) {
QString conjunction) const {
Expression exp = Expression(this->where(conditions, conjunction, false, "id",
false));
for (auto i = conditions.constBegin(); i != conditions.constEnd(); ++i) {
......
}
Expression QueryBuilder::where(QString condition,
QHash<QString, QVariant> values) {
QHash<QString, QVariant> values) const {
Expression exp = Expression(condition);
for (auto i = values.constBegin(); i != values.constEnd(); ++i) {
exp.appendParam(i.key(), i.value());
......
}
Expression QueryBuilder::between(QString column, QVariant firstValue,
QVariant secondValue) {
QVariant secondValue) const {
QString firstPh = column + "_bet1";
QString secondPh = column + "_bet2";
return this->appendCondition(firstPh, secondPh, firstValue, secondValue,
......
}
Expression QueryBuilder::notBetween(QString column, QVariant firstValue,
QVariant secondValue) {
QVariant secondValue) const {
QString firstPh = column + "_nbet1";
QString secondPh = column + "_nbet2";
return this->appendCondition(firstPh, secondPh, firstValue, secondValue,
......
Expression QueryBuilder::appendCondition(QString ph1, QString ph2,
QVariant val1, QVariant val2, QString condition) {
QVariant val1, QVariant val2, QString condition) const {
Expression exp = Expression(condition);
exp.appendParam(ph1, val1);
exp.appendParam(ph2, val2);
return exp;
}
Expression QueryBuilder::in(QString column, QList<QVariant> values) {
Expression QueryBuilder::in(QString column, QList<QVariant> values) const {
return this->inFunction(column, values);
}
Expression QueryBuilder::notIn(QString column, QList<QVariant> values) {
Expression QueryBuilder::notIn(QString column, QList<QVariant> values) const {
return this->inFunction(column, values, true);
}
Expression QueryBuilder::notOperator(QString op, QString column,
QVariant value) const {
Expression e = this->arbitraryOperator(op, column, value);
e.setExpression(this->notKeyword() + " " + e.getExpression());
return e;
}
Expression QueryBuilder::orOperator(
QHash<QString, QVariant> conditions, bool like) {
QHash<QString, QVariant> conditions, bool like) const {
Expression exp = Expression();
if (!conditions.isEmpty()) {
QString condition = "(";
......
return exp;
}
Expression QueryBuilder::orOperator() const {
return this->plainOr();
}
Expression QueryBuilder::norOperator() const {
return this->plainNor();
}
QString QueryBuilder::where(const QSharedPointer<Entity> &entity,
QString conjunction,
bool ignoreID) const {
src/querybuilder.h
bool ignoreID = false, const QString &primaryKey = QStringLiteral("id")) const;
void bindValue(const QString &key, const QVariant &value, QSqlQuery &q) const;
Expression where(QString column, QVariant value);
Join joinClasses(const QSharedPointer<Entity> &mainEntity, const QSharedPointer<Entity> &foreignEntity, const QString &joinType=QStringLiteral("LEFT JOIN"))const;
Join joinClasses(const QSharedPointer<Entity> &mainEntity,
const QSharedPointer<Entity> &foreignEntity,
const QString &joinType = QStringLiteral("LEFT JOIN"))const;
QList<Join> joinBaseClasses(const QSharedPointer<Entity> &entity);
/**
* @brief where
......
* @param conjunction its AND or OR
*/
Expression where(QHash<QString, QVariant> conditions,
QString conjunction = QStringLiteral("AND"));
QString conjunction = QStringLiteral("AND")) const;
Expression where(QString condition,
QHash<QString, QVariant> values = QHash<QString, QVariant>());
QHash<QString, QVariant> values = QHash<QString, QVariant>()) const;
//void where(Query &query,QHash<QString, QList<QVariant>> conditions, QString concat="AND");
Expression between(QString column, QVariant firstValue,
QVariant secondValue);
QVariant secondValue) const;
Expression notBetween(QString column, QVariant firstValue,
QVariant secondValue);
Expression in(QString column, QList<QVariant> values);
Expression notIn(QString column, QList<QVariant> values);
Expression notOperator(QString column, QVariant value);
QVariant secondValue) const;
Expression in(QString column, QList<QVariant> values) const;
Expression notIn(QString column, QList<QVariant> values) const;
Expression notOperator(QString op, QString column,
QVariant value) const;
Expression orOperator(QHash<QString, QVariant> conditions,
bool like = false);
Expression andOperator(QHash<QString, QVariant> conditions);
bool like = false) const;
Expression orOperator() const;
Expression norOperator() const;
Expression andOperator(QHash<QString, QVariant> conditions) const;
Expression andOperator() const;
Expression nandOperator() const;
/**
* @brief arbitraryOperator
* @param query
......
* @param value
*/
Expression arbitraryOperator(QString op, QString column,
QVariant value);
Expression isNull(QString column);
Expression isNotNull(QString column);
QVariant value) const;
Expression isNull(QString column) const;
Expression isNotNull(QString column) const;
Expression plainOr(); //adds a simple OR to condition
Expression plainNor();
Expression plainAnd(); //add a simple AND to condition
Expression plainNand();
Expression plainOr() const; //adds a simple OR to condition
Expression plainNor() const;
Expression plainAnd() const; //add a simple AND to condition
Expression plainNand() const;
/**
* Generates 'foo' LIKE "%bar%"
* @brief like
......
QString where(const QSharedPointer<Entity> &entity, QString conjunction = ",",
bool ignoreID = false) const;
QString where(const QHash<QString, QVariant> &m,
const QString &conjunction = ",",
const QString &conjunction,
bool ignoreID = false, const QString &primaryKey = "id",
bool withKeyword = true) const;
QString attributes(const QHash<QString, QVariant> &m,
......
const QSharedPointer<Entity> &entity) const;
QString leftJoin(const QString &foreignTable, const QString &tableName,
const QString &foreignKey = "id", const QString &primaryKey = "id", bool onlyCondition=false) const;
const QString &foreignKey = "id", const QString &primaryKey = "id",
bool onlyCondition = false) const;
QString superClassColumnName(const QMetaObject *&superMeta) const;
QString addWildcard(QVariant var, JokerPosition jp,
QChar jokerChar = '%') const;
......
virtual QString whereKeyword() const;
virtual QString countKeyword() const;
virtual Expression inFunction(QString column, QList<QVariant> values,
bool notOp = false);
bool notOp = false) const;
virtual QString between(QString colName, QString valName1, QString valName2,
bool notOp = false);
bool notOp = false) const;
virtual QString likeKeyword() const;
virtual QString limitKeyword() const;
virtual QString offsetKeyword() const;
QString appendNot(bool notOp);
QString appendNot(bool notOp) const;
virtual Expression appendCondition(QString ph1, QString ph2, QVariant val1,
QVariant val2, QString condition);
QVariant val2, QString condition) const;
QString entityClassname() const;
QString separator;
QSharedPointer<Schema> schema;

Auch abrufbar als: Unified diff