Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision dbf92b46

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID dbf92b46962b690efc729933026c728feb5f6492
  • Vorgänger 612083d3
  • Nachfolger 8925defa

some comfort methods for query builder

Unterschiede anzeigen:

src/querybuilder.cpp
QSqlQuery q = this->database->getQuery(this->selectBase(QStringList(
entity->getTablename())) + this->joinSuperClasses(
entity) + " WHERE " + this->schema->quoteColumnName(entity->getTablename() + "."
+ pk) + "= " + this->placeHolder(pk) + this->limit(1, offset));
+ pk) + this->equalOperator() + " " + this->placeHolder(pk) + this->limit(1, offset));
this->bindValue(pk, id, q);
return q;
}
......
sql += " " + this->whereKeyword() + " ";
sql += this->schema->quoteColumnName(
attribute);
sql += " = " + this->placeHolder(pk) + ";";
sql += " " + this->equalOperator()+" " + this->placeHolder(pk) + ";";
q.prepare(sql);
this->bindValue(pk, id, q);
return q;
......
QString pkCol = "id";
QString sql = "DELETE FROM " + this->schema->quoteTableName(
tableName) + " WHERE " + this->schema->quoteColumnName(
attribute) + "=" + this->placeHolder(pkCol);
attribute) + this->equalOperator() + this->placeHolder(pkCol);
q.prepare(sql);
this->bindValue(pkCol, id, q);
return q;
......
return "COUNT";
}
QString QueryBuilder::notEqualOperator() const {
return "!=";
}
QString QueryBuilder::equalOperator() const {
return "=";
}
QString QueryBuilder::fromKeyword() const {
return "FROM";
}
QString QueryBuilder::isNullKeywords() const {
return "IS NULL";
}
QString QueryBuilder::isNotNullKeywords() const {
return "IS NOT NULL";
}
Expression QueryBuilder::inFunction(QString column,
QList<QVariant> values, bool notOp) const {
QString condition = "";
......
ignoreID, primaryKey);
}
QString QueryBuilder::where(const QString &key, const QVariant &var, bool withKeyword, bool select, bool notEqual) const {
QString r = (withKeyword ? " WHERE " : "");
r += this->schema->quoteColumnName(key) + (var.isNull() && select
? (" " +(notEqual ? this->isNotNullKeywords(): this->isNullKeywords()))
: (notEqual ? this->notEqualOperator() : this->equalOperator() ) + this->placeHolder(key));
return r;
}
QString QueryBuilder::attributes(const QHash<QString, QVariant> &m, bool select,
const QString &conjunction,
bool ignoreID, const QString &primaryKey) const {
......
if (!rc.isEmpty()) {
rc += " " + conjunction + " ";
}
rc += this->schema->quoteColumnName(i.key()) + (i.value().isNull()
&& select ? " is null"
: "=" + this->placeHolder(i.key()));
rc += this->where(i.key(), i.value(), false, select);
}
}
return rc;
......
}
Expression QueryBuilder::isNull(QString column) const {
return Expression(this->schema->quoteColumnName(column) + " IS NULL");
return Expression(this->schema->quoteColumnName(column) + this->isNullKeywords());
}
Expression QueryBuilder::isNotNull(QString column) const {
return Expression(this->schema->quoteColumnName(column) + " IS " +
this->notKeyword() + " NULL");
return Expression(this->schema->quoteColumnName(column) + this->isNotNullKeywords());
}
Expression QueryBuilder::plainOr() const {
......
return exp;
}
Expression QueryBuilder::equal(QString &key, QVariant &value) {
Expression exp = Expression(this->where(key, value, false, true, false));
exp.appendParam(key,value);
return exp;
}
Expression QueryBuilder::notEqual(QString &key, QVariant &value) {
Expression exp = Expression(this->where(key, value, false, true, true));
exp.appendParam(key,value);
return exp;
}
Expression QueryBuilder::between(QString column, QVariant firstValue,
QVariant secondValue) const {
QString firstPh = column + "_bet1";
......
condition += " " + this->orKeyword() + " ";
}
condition += this->schema->quoteColumnName(i.key()) + (like ? " " +
this->likeKeyword() + " " : "=") +
this->likeKeyword() + " " : this->equalOperator()) +
this->placeHolder(i.key());
exp.appendParam(i.key(), i.value());
}

Auch abrufbar als: Unified diff