mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-24 11:49:14 -05:00
all where methods can take expression for column
All column parameters in where methods can take expressions, it's amazing how it progresses and how everything fits together. 🤔🔥 - added unit tests to test expressions for where methods
This commit is contained in:
@@ -46,6 +46,8 @@ namespace Query
|
||||
// virtual QString wrap(const Expression &value, bool prefixAlias = false) const;
|
||||
/*! Wrap a value in keyword identifiers. */
|
||||
QString wrap(const QVariant &value) const;
|
||||
/*! Wrap a value in keyword identifiers. */
|
||||
QString wrap(const Column &value) const;
|
||||
|
||||
/*! Wrap a table in keyword identifiers. */
|
||||
QString wrapTable(const QString &table) const;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <range/v3/algorithm/unique.hpp>
|
||||
#endif
|
||||
|
||||
#include "orm/query/expression.hpp"
|
||||
#include "orm/utils/export.hpp"
|
||||
|
||||
// TODO divide OrmTypes to internal and types which user will / may need, so divide to two files silverqx
|
||||
@@ -27,10 +28,14 @@ namespace Orm
|
||||
namespace Query
|
||||
{
|
||||
class Builder;
|
||||
class Expression;
|
||||
}
|
||||
using QueryBuilder = Query::Builder;
|
||||
|
||||
/*! Type for the database column. */
|
||||
using Column = std::variant<QString, Query::Expression>;
|
||||
/*! Columns vector. */
|
||||
using ColumnList = QVector<Column>;
|
||||
|
||||
/*! From clause defined in the QueryBuilder. */
|
||||
using FromClause = std::variant<std::monostate, QString, Query::Expression>;
|
||||
|
||||
@@ -65,14 +70,14 @@ namespace Query
|
||||
|
||||
struct WhereConditionItem
|
||||
{
|
||||
QString column;
|
||||
Column column;
|
||||
QVariant value {};
|
||||
QString comparison {"="};
|
||||
QString condition {"and"};
|
||||
WhereType type {WhereType::UNDEFINED};
|
||||
QSharedPointer<QueryBuilder> nestedQuery {nullptr};
|
||||
QVector<QVariant> values {};
|
||||
QString columnTwo {};
|
||||
Column columnTwo {};
|
||||
};
|
||||
|
||||
enum struct HavingType
|
||||
@@ -121,7 +126,7 @@ namespace Query
|
||||
|
||||
struct SHAREDLIB_EXPORT WhereItem
|
||||
{
|
||||
QString column;
|
||||
Column column;
|
||||
QVariant value;
|
||||
QString comparison {"="};
|
||||
QString condition {};
|
||||
@@ -131,8 +136,8 @@ namespace Query
|
||||
|
||||
struct WhereColumnItem
|
||||
{
|
||||
QString first;
|
||||
QString second;
|
||||
Column first;
|
||||
Column second;
|
||||
QString comparison {"="};
|
||||
QString condition {};
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "orm/ormtypes.hpp"
|
||||
#include "orm/query/grammars/grammar.hpp"
|
||||
#include "orm/query/expression.hpp"
|
||||
|
||||
#ifdef TINYORM_COMMON_NAMESPACE
|
||||
namespace TINYORM_COMMON_NAMESPACE
|
||||
@@ -189,16 +188,16 @@ namespace Query
|
||||
const QString &comparison, const QVariant &second);
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
Builder &where(const QString &column, const QString &comparison,
|
||||
Builder &where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition = "and");
|
||||
/*! Add an "or where" clause to the query. */
|
||||
Builder &orWhere(const QString &column, const QString &comparison,
|
||||
Builder &orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value);
|
||||
/*! Add a basic equal where clause to the query. */
|
||||
Builder &whereEq(const QString &column, const QVariant &value,
|
||||
Builder &whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause to the query. */
|
||||
Builder &orWhereEq(const QString &column, const QVariant &value);
|
||||
Builder &orWhereEq(const Column &column, const QVariant &value);
|
||||
|
||||
/*! Add a nested where clause to the query. */
|
||||
Builder &where(const std::function<void(Builder &)> &callback,
|
||||
@@ -219,48 +218,48 @@ namespace Query
|
||||
Builder &orWhereColumn(const QVector<WhereColumnItem> &values);
|
||||
|
||||
/*! Add a "where" clause comparing two columns to the query. */
|
||||
Builder &whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition = "and");
|
||||
Builder &whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition = "and");
|
||||
/*! Add a "or where" clause comparing two columns to the query. */
|
||||
Builder &orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second);
|
||||
Builder &orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second);
|
||||
/*! Add an equal "where" clause comparing two columns to the query. */
|
||||
Builder &whereColumnEq(const QString &first, const QString &second,
|
||||
Builder &whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause comparing two columns to the query. */
|
||||
Builder &orWhereColumnEq(const QString &first, const QString &second);
|
||||
Builder &orWhereColumnEq(const Column &first, const Column &second);
|
||||
|
||||
/*! Add a "where in" clause to the query. */
|
||||
Builder &whereIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &whereIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where in" clause to the query. */
|
||||
Builder &orWhereIn(const QString &column, const QVector<QVariant> &values);
|
||||
Builder &orWhereIn(const Column &column, const QVector<QVariant> &values);
|
||||
/*! Add a "where not in" clause to the query. */
|
||||
Builder &whereNotIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &whereNotIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not in" clause to the query. */
|
||||
Builder &orWhereNotIn(const QString &column, const QVector<QVariant> &values);
|
||||
Builder &orWhereNotIn(const Column &column, const QVector<QVariant> &values);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
Builder &whereNull(const QString &column, const QString &condition = "and",
|
||||
Builder &whereNull(const Column &column, const QString &condition = "and",
|
||||
bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
Builder &orWhereNull(const QString &column);
|
||||
Builder &orWhereNull(const Column &column);
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
Builder &whereNotNull(const QString &column, const QString &condition = "and");
|
||||
Builder &whereNotNull(const Column &column, const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
Builder &orWhereNotNull(const QString &column);
|
||||
Builder &orWhereNotNull(const Column &column);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
Builder &whereNull(const QStringList &columns = {"*"},
|
||||
Builder &whereNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
Builder &orWhereNull(const QStringList &columns = {"*"});
|
||||
Builder &orWhereNull(const QVector<Column> &columns = {"*"});
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
Builder &whereNotNull(const QStringList &columns = {"*"},
|
||||
Builder &whereNotNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
Builder &orWhereNotNull(const QStringList &columns = {"*"});
|
||||
Builder &orWhereNotNull(const QVector<Column> &columns = {"*"});
|
||||
|
||||
/*! Add a "group by" clause to the query. */
|
||||
Builder &groupBy(const QStringList &groups);
|
||||
|
||||
+44
-44
@@ -331,19 +331,19 @@ namespace Relations {
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
where(const QString &column, const QString &comparison,
|
||||
where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition = "and");
|
||||
/*! Add an "or where" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhere(const QString &column, const QString &comparison,
|
||||
orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value);
|
||||
/*! Add a basic equal where clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereEq(const QString &column, const QVariant &value,
|
||||
whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereEq(const QString &column, const QVariant &value);
|
||||
orWhereEq(const Column &column, const QVariant &value);
|
||||
|
||||
/*! Add a nested where clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
@@ -370,63 +370,63 @@ namespace Relations {
|
||||
|
||||
/*! Add a "where" clause comparing two columns to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition = "and");
|
||||
whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition = "and");
|
||||
/*! Add a "or where" clause comparing two columns to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second);
|
||||
orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second);
|
||||
/*! Add an equal "where" clause comparing two columns to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereColumnEq(const QString &first, const QString &second,
|
||||
whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause comparing two columns to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereColumnEq(const QString &first, const QString &second);
|
||||
orWhereColumnEq(const Column &first, const Column &second);
|
||||
|
||||
/*! Add a "where in" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereIn(const QString &column, const QVector<QVariant> &values,
|
||||
whereIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where in" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereIn(const QString &column, const QVector<QVariant> &values);
|
||||
orWhereIn(const Column &column, const QVector<QVariant> &values);
|
||||
/*! Add a "where not in" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereNotIn(const QString &column, const QVector<QVariant> &values,
|
||||
whereNotIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not in" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereNotIn(const QString &column, const QVector<QVariant> &values);
|
||||
orWhereNotIn(const Column &column, const QVector<QVariant> &values);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereNull(const QString &column, const QString &condition = "and",
|
||||
whereNull(const Column &column, const QString &condition = "and",
|
||||
bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereNull(const QString &column);
|
||||
orWhereNull(const Column &column);
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereNotNull(const QString &column, const QString &condition = "and");
|
||||
whereNotNull(const Column &column, const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereNotNull(const QString &column);
|
||||
orWhereNotNull(const Column &column);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereNull(const QStringList &columns = {"*"},
|
||||
whereNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereNull(const QStringList &columns = {"*"});
|
||||
orWhereNull(const QVector<Column> &columns = {"*"});
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereNotNull(const QStringList &columns = {"*"},
|
||||
whereNotNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
orWhereNotNull(const QStringList &columns = {"*"});
|
||||
orWhereNotNull(const QVector<Column> &columns = {"*"});
|
||||
|
||||
/*! Add a "group by" clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
@@ -1820,7 +1820,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::where(
|
||||
const QString &column, const QString &comparison,
|
||||
const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
@@ -1833,7 +1833,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhere(
|
||||
const QString &column, const QString &comparison, const QVariant &value)
|
||||
const Column &column, const QString &comparison, const QVariant &value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1845,7 +1845,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereEq(
|
||||
const QString &column, const QVariant &value, const QString &condition)
|
||||
const Column &column, const QVariant &value, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1857,7 +1857,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereEq(
|
||||
const QString &column, const QVariant &value)
|
||||
const Column &column, const QVariant &value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1894,7 +1894,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::where(const QVector<WhereItem> &values,
|
||||
const QString &condition)
|
||||
const QString &condition)
|
||||
{
|
||||
/* The parentheses in this query are ok:
|
||||
select * from xyz where (id = ?) */
|
||||
@@ -1943,8 +1943,8 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereColumn(
|
||||
const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition)
|
||||
const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1956,7 +1956,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereColumn(
|
||||
const QString &first, const QString &comparison, const QString &second)
|
||||
const Column &first, const QString &comparison, const Column &second)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1968,7 +1968,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereColumnEq(
|
||||
const QString &first, const QString &second, const QString &condition)
|
||||
const Column &first, const Column &second, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1980,7 +1980,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereColumnEq(
|
||||
const QString &first, const QString &second)
|
||||
const Column &first, const Column &second)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -1992,7 +1992,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereIn(
|
||||
const QString &column, const QVector<QVariant> &values,
|
||||
const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition, const bool nope)
|
||||
{
|
||||
auto builder = query();
|
||||
@@ -2005,7 +2005,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereIn(
|
||||
const QString &column, const QVector<QVariant> &values)
|
||||
const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2017,7 +2017,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereNotIn(
|
||||
const QString &column, const QVector<QVariant> &values,
|
||||
const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
@@ -2030,7 +2030,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereNotIn(
|
||||
const QString &column, const QVector<QVariant> &values)
|
||||
const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2042,7 +2042,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereNull(
|
||||
const QString &column, const QString &condition, const bool nope)
|
||||
const Column &column, const QString &condition, const bool nope)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2053,7 +2053,7 @@ namespace Relations {
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereNull(const QString &column)
|
||||
Model<Derived, AllRelations...>::orWhereNull(const Column &column)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2065,7 +2065,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereNotNull(
|
||||
const QString &column, const QString &condition)
|
||||
const Column &column, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2076,7 +2076,7 @@ namespace Relations {
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereNotNull(const QString &column)
|
||||
Model<Derived, AllRelations...>::orWhereNotNull(const Column &column)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2088,7 +2088,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereNull(
|
||||
const QStringList &columns, const QString &condition, const bool nope)
|
||||
const QVector<Column> &columns, const QString &condition, const bool nope)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2099,7 +2099,7 @@ namespace Relations {
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereNull(const QStringList &columns)
|
||||
Model<Derived, AllRelations...>::orWhereNull(const QVector<Column> &columns)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2111,7 +2111,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::whereNotNull(
|
||||
const QStringList &columns, const QString &condition)
|
||||
const QVector<Column> &columns, const QString &condition)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -2122,7 +2122,7 @@ namespace Relations {
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::orWhereNotNull(const QStringList &columns)
|
||||
Model<Derived, AllRelations...>::orWhereNotNull(const QVector<Column> &columns)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
|
||||
@@ -278,16 +278,16 @@ namespace Relations
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
const Relation &where(
|
||||
const QString &column, const QString &comparison,
|
||||
const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition = "and") const;
|
||||
/*! Add an "or where" clause to the query. */
|
||||
const Relation &orWhere(const QString &column, const QString &comparison,
|
||||
const Relation &orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value) const;
|
||||
/*! Add a basic equal where clause to the query. */
|
||||
const Relation &whereEq(const QString &column, const QVariant &value,
|
||||
const Relation &whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition = "and") const;
|
||||
/*! Add an equal "or where" clause to the query. */
|
||||
const Relation &orWhereEq(const QString &column, const QVariant &value) const;
|
||||
const Relation &orWhereEq(const Column &column, const QVariant &value) const;
|
||||
|
||||
/*! Add a nested where clause to the query. */
|
||||
const Relation &where(const std::function<void(Builder<Related> &)> &callback,
|
||||
@@ -309,57 +309,57 @@ namespace Relations
|
||||
const Relation &orWhereColumn(const QVector<WhereColumnItem> &values) const;
|
||||
|
||||
/*! Add a "where" clause comparing two columns to the query. */
|
||||
const Relation &whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second,
|
||||
const Relation &whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second,
|
||||
const QString &condition = "and") const;
|
||||
/*! Add a "or where" clause comparing two columns to the query. */
|
||||
const Relation &orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second) const;
|
||||
const Relation &orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second) const;
|
||||
/*! Add an equal "where" clause comparing two columns to the query. */
|
||||
const Relation &whereColumnEq(const QString &first, const QString &second,
|
||||
const Relation &whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition = "and") const;
|
||||
/*! Add an equal "or where" clause comparing two columns to the query. */
|
||||
const Relation &orWhereColumnEq(const QString &first,
|
||||
const QString &second) const;
|
||||
const Relation &orWhereColumnEq(const Column &first,
|
||||
const Column &second) const;
|
||||
|
||||
/*! Add a "where in" clause to the query. */
|
||||
const Relation &whereIn(
|
||||
const QString &column, const QVector<QVariant> &values,
|
||||
const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and", bool nope = false) const;
|
||||
/*! Add an "or where in" clause to the query. */
|
||||
const Relation &orWhereIn(const QString &column,
|
||||
const Relation &orWhereIn(const Column &column,
|
||||
const QVector<QVariant> &values) const;
|
||||
/*! Add a "where not in" clause to the query. */
|
||||
const Relation &whereNotIn(const QString &column,
|
||||
const Relation &whereNotIn(const Column &column,
|
||||
const QVector<QVariant> &values,
|
||||
const QString &condition = "and") const;
|
||||
/*! Add an "or where not in" clause to the query. */
|
||||
const Relation &orWhereNotIn(const QString &column,
|
||||
const Relation &orWhereNotIn(const Column &column,
|
||||
const QVector<QVariant> &values) const;
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
const Relation &whereNull(const QString &column,
|
||||
const Relation &whereNull(const Column &column,
|
||||
const QString &condition = "and",
|
||||
bool nope = false) const;
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
const Relation &orWhereNull(const QString &column) const;
|
||||
const Relation &orWhereNull(const Column &column) const;
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
const Relation &whereNotNull(const QString &column,
|
||||
const Relation &whereNotNull(const Column &column,
|
||||
const QString &condition = "and") const;
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
const Relation &orWhereNotNull(const QString &column) const;
|
||||
const Relation &orWhereNotNull(const Column &column) const;
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
const Relation &whereNull(const QStringList &columns = {"*"},
|
||||
const Relation &whereNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and",
|
||||
bool nope = false) const;
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
const Relation &orWhereNull(const QStringList &columns = {"*"}) const;
|
||||
const Relation &orWhereNull(const QVector<Column> &columns = {"*"}) const;
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
const Relation &whereNotNull(const QStringList &columns = {"*"},
|
||||
const Relation &whereNotNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and") const;
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
const Relation &orWhereNotNull(const QStringList &columns = {"*"}) const;
|
||||
const Relation &orWhereNotNull(const QVector<Column> &columns = {"*"}) const;
|
||||
|
||||
/*! Add a "group by" clause to the query. */
|
||||
const Relation &groupBy(const QStringList &groups) const;
|
||||
@@ -969,7 +969,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::where(const QString &column, const QString &comparison,
|
||||
Relation<Model, Related>::where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition) const
|
||||
{
|
||||
m_query->where(column, comparison, value, condition);
|
||||
@@ -979,7 +979,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhere(const QString &column, const QString &comparison,
|
||||
Relation<Model, Related>::orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value) const
|
||||
{
|
||||
m_query->orWhere(column, comparison, value);
|
||||
@@ -989,7 +989,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereEq(const QString &column, const QVariant &value,
|
||||
Relation<Model, Related>::whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition) const
|
||||
{
|
||||
m_query->whereEq(column, value, condition);
|
||||
@@ -999,7 +999,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereEq(const QString &column,
|
||||
Relation<Model, Related>::orWhereEq(const Column &column,
|
||||
const QVariant &value) const
|
||||
{
|
||||
m_query->orWhereEq(column, value);
|
||||
@@ -1069,8 +1069,8 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereColumn(
|
||||
const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition) const
|
||||
const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition) const
|
||||
{
|
||||
m_query->whereColumn(first, comparison, second, condition);
|
||||
|
||||
@@ -1080,7 +1080,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereColumn(
|
||||
const QString &first, const QString &comparison, const QString &second) const
|
||||
const Column &first, const QString &comparison, const Column &second) const
|
||||
{
|
||||
m_query->orWhereColumn(first, comparison, second);
|
||||
|
||||
@@ -1090,7 +1090,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereColumnEq(
|
||||
const QString &first, const QString &second, const QString &condition) const
|
||||
const Column &first, const Column &second, const QString &condition) const
|
||||
{
|
||||
m_query->whereColumnEq(first, second, condition);
|
||||
|
||||
@@ -1099,8 +1099,8 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereColumnEq(const QString &first,
|
||||
const QString &second) const
|
||||
Relation<Model, Related>::orWhereColumnEq(const Column &first,
|
||||
const Column &second) const
|
||||
{
|
||||
m_query->orWhereColumnEq(first, second);
|
||||
|
||||
@@ -1110,7 +1110,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereIn(
|
||||
const QString &column, const QVector<QVariant> &values,
|
||||
const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition, const bool nope) const
|
||||
{
|
||||
m_query->whereIn(column, values, condition, nope);
|
||||
@@ -1120,7 +1120,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereIn(const QString &column,
|
||||
Relation<Model, Related>::orWhereIn(const Column &column,
|
||||
const QVector<QVariant> &values) const
|
||||
{
|
||||
m_query->orWhereIn(column, values);
|
||||
@@ -1131,7 +1131,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereNotIn(
|
||||
const QString &column, const QVector<QVariant> &values,
|
||||
const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition) const
|
||||
{
|
||||
m_query->whereNotIn(column, values, condition);
|
||||
@@ -1141,7 +1141,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereNotIn(const QString &column,
|
||||
Relation<Model, Related>::orWhereNotIn(const Column &column,
|
||||
const QVector<QVariant> &values) const
|
||||
{
|
||||
m_query->orWhereNotIn(column, values);
|
||||
@@ -1152,7 +1152,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereNull(
|
||||
const QString &column, const QString &condition, const bool nope) const
|
||||
const Column &column, const QString &condition, const bool nope) const
|
||||
{
|
||||
m_query->whereNull(column, condition, nope);
|
||||
|
||||
@@ -1161,7 +1161,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereNull(const QString &column) const
|
||||
Relation<Model, Related>::orWhereNull(const Column &column) const
|
||||
{
|
||||
m_query->orWhereNull(column);
|
||||
|
||||
@@ -1170,7 +1170,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereNotNull(const QString &column,
|
||||
Relation<Model, Related>::whereNotNull(const Column &column,
|
||||
const QString &condition) const
|
||||
{
|
||||
m_query->whereNotNull(column, condition);
|
||||
@@ -1180,7 +1180,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereNotNull(const QString &column) const
|
||||
Relation<Model, Related>::orWhereNotNull(const Column &column) const
|
||||
{
|
||||
m_query->orWhereNotNull(column);
|
||||
|
||||
@@ -1190,7 +1190,8 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereNull(
|
||||
const QStringList &columns, const QString &condition, const bool nope) const
|
||||
const QVector<Column> &columns, const QString &condition,
|
||||
const bool nope) const
|
||||
{
|
||||
m_query->whereNull(columns, condition, nope);
|
||||
|
||||
@@ -1199,7 +1200,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereNull(const QStringList &columns) const
|
||||
Relation<Model, Related>::orWhereNull(const QVector<Column> &columns) const
|
||||
{
|
||||
m_query->orWhereNull(columns);
|
||||
|
||||
@@ -1208,7 +1209,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::whereNotNull(const QStringList &columns,
|
||||
Relation<Model, Related>::whereNotNull(const QVector<Column> &columns,
|
||||
const QString &condition) const
|
||||
{
|
||||
m_query->whereNotNull(columns, condition);
|
||||
@@ -1218,7 +1219,7 @@ namespace Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::orWhereNotNull(const QStringList &columns) const
|
||||
Relation<Model, Related>::orWhereNotNull(const QVector<Column> &columns) const
|
||||
{
|
||||
m_query->orWhereNotNull(columns);
|
||||
|
||||
|
||||
@@ -206,16 +206,16 @@ namespace Relations
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
Builder &where(const QString &column, const QString &comparison,
|
||||
Builder &where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition = "and");
|
||||
/*! Add an "or where" clause to the query. */
|
||||
Builder &orWhere(const QString &column, const QString &comparison,
|
||||
Builder &orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value);
|
||||
/*! Add a basic equal where clause to the query. */
|
||||
Builder &whereEq(const QString &column, const QVariant &value,
|
||||
Builder &whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause to the query. */
|
||||
Builder &orWhereEq(const QString &column, const QVariant &value);
|
||||
Builder &orWhereEq(const Column &column, const QVariant &value);
|
||||
|
||||
/*! Add a nested where clause to the query. */
|
||||
Builder &where(const std::function<void(Builder &)> &callback,
|
||||
@@ -236,48 +236,48 @@ namespace Relations
|
||||
Builder &orWhereColumn(const QVector<WhereColumnItem> &values);
|
||||
|
||||
/*! Add a "where" clause comparing two columns to the query. */
|
||||
Builder &whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition = "and");
|
||||
Builder &whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition = "and");
|
||||
/*! Add a "or where" clause comparing two columns to the query. */
|
||||
Builder &orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second);
|
||||
Builder &orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second);
|
||||
/*! Add an equal "where" clause comparing two columns to the query. */
|
||||
Builder &whereColumnEq(const QString &first, const QString &second,
|
||||
Builder &whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition = "and");
|
||||
/*! Add an equal "or where" clause comparing two columns to the query. */
|
||||
Builder &orWhereColumnEq(const QString &first, const QString &second);
|
||||
Builder &orWhereColumnEq(const Column &first, const Column &second);
|
||||
|
||||
/*! Add a "where in" clause to the query. */
|
||||
Builder &whereIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &whereIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where in" clause to the query. */
|
||||
Builder &orWhereIn(const QString &column, const QVector<QVariant> &values);
|
||||
Builder &orWhereIn(const Column &column, const QVector<QVariant> &values);
|
||||
/*! Add a "where not in" clause to the query. */
|
||||
Builder &whereNotIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &whereNotIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not in" clause to the query. */
|
||||
Builder &orWhereNotIn(const QString &column, const QVector<QVariant> &values);
|
||||
Builder &orWhereNotIn(const Column &column, const QVector<QVariant> &values);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
Builder &whereNull(const QString &column, const QString &condition = "and",
|
||||
Builder &whereNull(const Column &column, const QString &condition = "and",
|
||||
bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
Builder &orWhereNull(const QString &column);
|
||||
Builder &orWhereNull(const Column &column);
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
Builder &whereNotNull(const QString &column, const QString &condition = "and");
|
||||
Builder &whereNotNull(const Column &column, const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
Builder &orWhereNotNull(const QString &column);
|
||||
Builder &orWhereNotNull(const Column &column);
|
||||
|
||||
/*! Add a "where null" clause to the query. */
|
||||
Builder &whereNull(const QStringList &columns = {"*"},
|
||||
Builder &whereNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and", bool nope = false);
|
||||
/*! Add an "or where null" clause to the query. */
|
||||
Builder &orWhereNull(const QStringList &columns = {"*"});
|
||||
Builder &orWhereNull(const QVector<Column> &columns = {"*"});
|
||||
/*! Add a "where not null" clause to the query. */
|
||||
Builder &whereNotNull(const QStringList &columns = {"*"},
|
||||
Builder &whereNotNull(const QVector<Column> &columns = {"*"},
|
||||
const QString &condition = "and");
|
||||
/*! Add an "or where not null" clause to the query. */
|
||||
Builder &orWhereNotNull(const QStringList &columns = {"*"});
|
||||
Builder &orWhereNotNull(const QVector<Column> &columns = {"*"});
|
||||
|
||||
/*! Add a "group by" clause to the query. */
|
||||
Builder &groupBy(const QStringList &groups);
|
||||
@@ -946,7 +946,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::where(const QString &column, const QString &comparison,
|
||||
Builder<Model>::where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition)
|
||||
{
|
||||
toBase().where(column, comparison, value, condition);
|
||||
@@ -955,7 +955,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhere(const QString &column, const QString &comparison,
|
||||
Builder<Model>::orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value)
|
||||
{
|
||||
toBase().orWhere(column, comparison, value);
|
||||
@@ -964,7 +964,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereEq(const QString &column, const QVariant &value,
|
||||
Builder<Model>::whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition)
|
||||
{
|
||||
toBase().whereEq(column, value, condition);
|
||||
@@ -973,7 +973,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhereEq(const QString &column, const QVariant &value)
|
||||
Builder<Model>::orWhereEq(const Column &column, const QVariant &value)
|
||||
{
|
||||
toBase().orWhereEq(column, value);
|
||||
return *this;
|
||||
@@ -1035,8 +1035,8 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition)
|
||||
Builder<Model>::whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition)
|
||||
{
|
||||
toBase().whereColumn(first, comparison, second, condition);
|
||||
return *this;
|
||||
@@ -1044,8 +1044,8 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second)
|
||||
Builder<Model>::orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second)
|
||||
{
|
||||
toBase().orWhereColumn(first, comparison, second);
|
||||
return *this;
|
||||
@@ -1053,7 +1053,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereColumnEq(const QString &first, const QString &second,
|
||||
Builder<Model>::whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition)
|
||||
{
|
||||
toBase().whereColumnEq(first, second, condition);
|
||||
@@ -1062,7 +1062,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhereColumnEq(const QString &first, const QString &second)
|
||||
Builder<Model>::orWhereColumnEq(const Column &first, const Column &second)
|
||||
{
|
||||
toBase().orWhereColumnEq(first, second);
|
||||
return *this;
|
||||
@@ -1070,7 +1070,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder<Model>::whereIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition, const bool nope)
|
||||
{
|
||||
toBase().whereIn(column, values, condition, nope);
|
||||
@@ -1079,7 +1079,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhereIn(const QString &column, const QVector<QVariant> &values)
|
||||
Builder<Model>::orWhereIn(const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
toBase().orWhereIn(column, values);
|
||||
return *this;
|
||||
@@ -1087,7 +1087,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereNotIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder<Model>::whereNotIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition)
|
||||
{
|
||||
toBase().whereNotIn(column, values, condition);
|
||||
@@ -1096,7 +1096,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::orWhereNotIn(const QString &column, const QVector<QVariant> &values)
|
||||
Builder<Model>::orWhereNotIn(const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
toBase().orWhereNotIn(column, values);
|
||||
return *this;
|
||||
@@ -1104,7 +1104,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereNull(const QString &column, const QString &condition,
|
||||
Builder<Model>::whereNull(const Column &column, const QString &condition,
|
||||
const bool nope)
|
||||
{
|
||||
toBase().whereNull(column, condition, nope);
|
||||
@@ -1112,7 +1112,7 @@ namespace Relations
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &Builder<Model>::orWhereNull(const QString &column)
|
||||
Builder<Model> &Builder<Model>::orWhereNull(const Column &column)
|
||||
{
|
||||
toBase().orWhereNull(column);
|
||||
return *this;
|
||||
@@ -1120,14 +1120,14 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereNotNull(const QString &column, const QString &condition)
|
||||
Builder<Model>::whereNotNull(const Column &column, const QString &condition)
|
||||
{
|
||||
toBase().whereNotNull(column, condition);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &Builder<Model>::orWhereNotNull(const QString &column)
|
||||
Builder<Model> &Builder<Model>::orWhereNotNull(const Column &column)
|
||||
{
|
||||
toBase().orWhereNotNull(column);
|
||||
return *this;
|
||||
@@ -1135,7 +1135,7 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereNull(const QStringList &columns, const QString &condition,
|
||||
Builder<Model>::whereNull(const QVector<Column> &columns, const QString &condition,
|
||||
bool nope)
|
||||
{
|
||||
toBase().whereNull(columns, condition, nope);
|
||||
@@ -1143,7 +1143,7 @@ namespace Relations
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &Builder<Model>::orWhereNull(const QStringList &columns)
|
||||
Builder<Model> &Builder<Model>::orWhereNull(const QVector<Column> &columns)
|
||||
{
|
||||
toBase().orWhereNull(columns);
|
||||
return *this;
|
||||
@@ -1151,14 +1151,15 @@ namespace Relations
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::whereNotNull(const QStringList &columns, const QString &condition)
|
||||
Builder<Model>::whereNotNull(const QVector<Column> &columns,
|
||||
const QString &condition)
|
||||
{
|
||||
toBase().whereNotNull(columns, condition);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &Builder<Model>::orWhereNotNull(const QStringList &columns)
|
||||
Builder<Model> &Builder<Model>::orWhereNotNull(const QVector<Column> &columns)
|
||||
{
|
||||
toBase().orWhereNotNull(columns);
|
||||
return *this;
|
||||
|
||||
+11
-1
@@ -1,7 +1,6 @@
|
||||
#include "orm/basegrammar.hpp"
|
||||
|
||||
#include "orm/runtimeerror.hpp"
|
||||
#include "orm/query/expression.hpp"
|
||||
|
||||
#ifdef TINYORM_COMMON_NAMESPACE
|
||||
namespace TINYORM_COMMON_NAMESPACE
|
||||
@@ -51,10 +50,21 @@ QString BaseGrammar::wrap(const QString &value, const bool prefixAlias) const
|
||||
|
||||
QString BaseGrammar::wrap(const QVariant &value) const
|
||||
{
|
||||
// CUR remove after some time silverqx
|
||||
// TODO prod remove, it looks like this wrap overload is never called silverqx
|
||||
Q_ASSERT("wrap(QVariant");
|
||||
|
||||
return isExpression(value) ? getValue(value).value<QString>()
|
||||
: wrap(value.value<QString>());
|
||||
}
|
||||
|
||||
QString BaseGrammar::wrap(const Column &value) const
|
||||
{
|
||||
return std::holds_alternative<Expression>(value)
|
||||
? getValue(std::get<Expression>(value)).value<QString>()
|
||||
: wrap(std::get<QString>(value));
|
||||
}
|
||||
|
||||
QString BaseGrammar::wrapTable(const QString &table) const
|
||||
{
|
||||
return wrap(QStringLiteral("%1%2").arg(m_tablePrefix, table), true);
|
||||
|
||||
@@ -9,7 +9,9 @@ namespace Orm
|
||||
|
||||
WhereItem::operator AttributeItem() const
|
||||
{
|
||||
return {column, value};
|
||||
/* AttributeItem or more precise TinyORM attributes as such, can not contain
|
||||
expression in the column name. */
|
||||
return {std::get<QString>(column), value};
|
||||
}
|
||||
|
||||
bool operator==(const AttributeItem &lhs, const AttributeItem &rhs)
|
||||
|
||||
@@ -243,32 +243,33 @@ Builder &Builder::fromRaw(const QString &expression, const QVector<QVariant> &bi
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::where(const QString &column, const QString &comparison,
|
||||
Builder &Builder::where(const Column &column, const QString &comparison,
|
||||
const QVariant &value, const QString &condition)
|
||||
{
|
||||
// Compile check for a invalid comparison operator
|
||||
invalidOperator(comparison);
|
||||
|
||||
m_wheres.append({column, value, comparison, condition, WhereType::BASIC});
|
||||
m_wheres.append({.column = column, .value = value, .comparison = comparison,
|
||||
.condition = condition, .type = WhereType::BASIC});
|
||||
|
||||
addBinding(value, BindingType::WHERE);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::orWhere(const QString &column, const QString &comparison,
|
||||
Builder &Builder::orWhere(const Column &column, const QString &comparison,
|
||||
const QVariant &value)
|
||||
{
|
||||
return where(column, comparison, value, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereEq(const QString &column, const QVariant &value,
|
||||
Builder &Builder::whereEq(const Column &column, const QVariant &value,
|
||||
const QString &condition)
|
||||
{
|
||||
return where(column, QStringLiteral("="), value, condition);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereEq(const QString &column, const QVariant &value)
|
||||
Builder &Builder::orWhereEq(const Column &column, const QVariant &value)
|
||||
{
|
||||
return where(column, QStringLiteral("="), value, QStringLiteral("or"));
|
||||
}
|
||||
@@ -314,8 +315,8 @@ Builder &Builder::orWhereColumn(const QVector<WhereColumnItem> &values)
|
||||
return addArrayOfWheres(values, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second, const QString &condition)
|
||||
Builder &Builder::whereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second, const QString &condition)
|
||||
{
|
||||
// Compile check for a invalid comparison operator
|
||||
invalidOperator(comparison);
|
||||
@@ -326,24 +327,24 @@ Builder &Builder::whereColumn(const QString &first, const QString &comparison,
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereColumn(const QString &first, const QString &comparison,
|
||||
const QString &second)
|
||||
Builder &Builder::orWhereColumn(const Column &first, const QString &comparison,
|
||||
const Column &second)
|
||||
{
|
||||
return whereColumn(first, comparison, second, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereColumnEq(const QString &first, const QString &second,
|
||||
Builder &Builder::whereColumnEq(const Column &first, const Column &second,
|
||||
const QString &condition)
|
||||
{
|
||||
return whereColumn(first, QStringLiteral("="), second, condition);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereColumnEq(const QString &first, const QString &second)
|
||||
Builder &Builder::orWhereColumnEq(const Column &first, const Column &second)
|
||||
{
|
||||
return whereColumn(first, QStringLiteral("="), second, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &Builder::whereIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition, const bool nope)
|
||||
{
|
||||
const auto type = nope ? WhereType::NOT_IN : WhereType::IN_;
|
||||
@@ -359,44 +360,45 @@ Builder &Builder::whereIn(const QString &column, const QVector<QVariant> &values
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereIn(const QString &column, const QVector<QVariant> &values)
|
||||
Builder &Builder::orWhereIn(const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
return whereIn(column, values, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereNotIn(const QString &column, const QVector<QVariant> &values,
|
||||
Builder &Builder::whereNotIn(const Column &column, const QVector<QVariant> &values,
|
||||
const QString &condition)
|
||||
{
|
||||
return whereIn(column, values, condition, true);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereNotIn(const QString &column, const QVector<QVariant> &values)
|
||||
Builder &Builder::orWhereNotIn(const Column &column, const QVector<QVariant> &values)
|
||||
{
|
||||
return whereNotIn(column, values, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereNull(const QString &column, const QString &condition,
|
||||
Builder &Builder::whereNull(const Column &column, const QString &condition,
|
||||
const bool nope)
|
||||
{
|
||||
return whereNull(QStringList(column), condition, nope);
|
||||
return whereNull(QVector<Column> {column}, condition, nope);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereNull(const QString &column)
|
||||
Builder &Builder::orWhereNull(const Column &column)
|
||||
{
|
||||
return orWhereNull(QStringList(column));
|
||||
return orWhereNull(QVector<Column> {column});
|
||||
}
|
||||
|
||||
Builder &Builder::whereNotNull(const QString &column, const QString &condition)
|
||||
Builder &Builder::whereNotNull(const Column &column, const QString &condition)
|
||||
{
|
||||
return whereNotNull(QStringList(column), condition);
|
||||
return whereNotNull(QVector<Column> {column}, condition);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereNotNull(const QString &column)
|
||||
Builder &Builder::orWhereNotNull(const Column &column)
|
||||
{
|
||||
return orWhereNotNull(QStringList(column));
|
||||
return orWhereNotNull(QVector<Column> {column});
|
||||
}
|
||||
|
||||
Builder &Builder::whereNull(const QStringList &columns, const QString &condition,
|
||||
// CUR reorder above Column versions silverqx
|
||||
Builder &Builder::whereNull(const QVector<Column> &columns, const QString &condition,
|
||||
const bool nope)
|
||||
{
|
||||
const auto type = nope ? WhereType::NOT_NULL : WhereType::NULL_;
|
||||
@@ -407,17 +409,17 @@ Builder &Builder::whereNull(const QStringList &columns, const QString &condition
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereNull(const QStringList &columns)
|
||||
Builder &Builder::orWhereNull(const QVector<Column> &columns)
|
||||
{
|
||||
return whereNull(columns, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
Builder &Builder::whereNotNull(const QStringList &columns, const QString &condition)
|
||||
Builder &Builder::whereNotNull(const QVector<Column> &columns, const QString &condition)
|
||||
{
|
||||
return whereNull(columns, condition, true);
|
||||
}
|
||||
|
||||
Builder &Builder::orWhereNotNull(const QStringList &columns)
|
||||
Builder &Builder::orWhereNotNull(const QVector<Column> &columns)
|
||||
{
|
||||
return whereNotNull(columns, QStringLiteral("or"));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ joinAttributesForFirstOr(const QVector<WhereItem> &attributes,
|
||||
auto attributesFiltered =
|
||||
attributes | views::remove_if([&keyName](const WhereItem &value)
|
||||
{
|
||||
return keyName == value.column;
|
||||
/* AttributeItem or more precise TinyORM attributes as such, can not contain
|
||||
expression in the column name.
|
||||
Of course, I could obtain the QString value from the expression and
|
||||
compare it, but I will not support that intentionally, instead
|
||||
the std::bad_variant_access exception will be thrown. */
|
||||
return keyName == std::get<QString>(value.column);
|
||||
})
|
||||
| ranges::to<QVector<AttributeItem>>();
|
||||
|
||||
|
||||
@@ -52,21 +52,27 @@ private slots:
|
||||
void whereWithVectorValue() const;
|
||||
|
||||
void basicOrWhere() const;
|
||||
void basicOrWhere_ColumnExpression() const;
|
||||
void orWhereWithVectorValue() const;
|
||||
void orWhereWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void whereColumn() const;
|
||||
void orWhereColumn() const;
|
||||
void orWhereColumn_ColumnExpression() const;
|
||||
void whereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void basicWhereIn() const;
|
||||
void basicWhereNotIn() const;
|
||||
void basicWhereNotIn_ColumnExpression() const;
|
||||
void emptyWhereIn() const;
|
||||
void emptyNotWhereIn() const;
|
||||
void rawWhereIn() const;
|
||||
void whereIn_ValueExpression() const;
|
||||
|
||||
void basicWhereNull() const;
|
||||
void basicWhereNotNull() const;
|
||||
void basicWhereNotNull_ColumnExpression() const;
|
||||
void whereNullWithVectorValue() const;
|
||||
void whereNotNullWithVectorValue() const;
|
||||
|
||||
@@ -699,6 +705,18 @@ void tst_MySql_QueryBuilder::basicOrWhere() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::basicOrWhere_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where(Raw("id"), ">", 4)
|
||||
.orWhereEq(Raw("`name`"), "test3");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrents` where id > ? or `name` = ?");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4), QVariant("test3")}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::orWhereWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -712,6 +730,20 @@ void tst_MySql_QueryBuilder::orWhereWithVectorValue() const
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::orWhereWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents")
|
||||
.where({{Raw("id"), 3}, {Raw("`size`"), 10, ">"}})
|
||||
.orWhere({{Raw("progress"), 100, ">="}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrents` where (id = ? and `size` > ?) or "
|
||||
"(progress >= ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::whereColumn() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -755,6 +787,20 @@ void tst_MySql_QueryBuilder::orWhereColumn() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::orWhereColumn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files")
|
||||
.whereColumnEq(Raw("filepath"), Raw("`note`"))
|
||||
.orWhereColumn(Raw("size"), ">", Raw("progress"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrent_previewable_files` where filepath = `note` "
|
||||
"or size > progress");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::whereColumnWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -826,6 +872,20 @@ void tst_MySql_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::orWhereColumnWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files").whereEq("id", 2)
|
||||
.orWhereColumn({{Raw("filepath"), Raw("`note`")},
|
||||
{"size", Raw("progress"), ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrent_previewable_files` "
|
||||
"where `id` = ? or (filepath = `note` or `size` > progress)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::basicWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -846,7 +906,8 @@ void tst_MySql_QueryBuilder::basicWhereIn() const
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrents` where `id` = ? or `id` in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,10 +931,23 @@ void tst_MySql_QueryBuilder::basicWhereNotIn() const
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrents` where `id` = ? or `id` not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::basicWhereNotIn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where("id", "=", 1)
|
||||
.orWhereNotIn(Raw("id"), {2, 3, 4});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrents` where `id` = ? or id not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::emptyWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -922,7 +996,7 @@ void tst_MySql_QueryBuilder::emptyNotWhereIn() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::rawWhereIn() const
|
||||
void tst_MySql_QueryBuilder::whereIn_ValueExpression() const
|
||||
{
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -1026,6 +1100,18 @@ void tst_MySql_QueryBuilder::basicWhereNotNull() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::basicWhereNotNull_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull(Raw("seeds"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrent_peers` where `id` = ? or seeds is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
|
||||
void tst_MySql_QueryBuilder::whereNullWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -1069,7 +1155,8 @@ void tst_MySql_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds", "total_seeds"});
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds",
|
||||
"total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from `torrent_peers` where `seeds` is not null "
|
||||
"and `total_seeds` is not null");
|
||||
|
||||
+135
-31
@@ -53,21 +53,27 @@ private slots:
|
||||
void whereWithVectorValue() const;
|
||||
|
||||
void basicOrWhere() const;
|
||||
void basicOrWhere_ColumnExpression() const;
|
||||
void orWhereWithVectorValue() const;
|
||||
void orWhereWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void whereColumn() const;
|
||||
void orWhereColumn() const;
|
||||
void orWhereColumn_ColumnExpression() const;
|
||||
void whereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void basicWhereIn() const;
|
||||
void basicWhereNotIn() const;
|
||||
void basicWhereNotIn_ColumnExpression() const;
|
||||
void emptyWhereIn() const;
|
||||
void emptyNotWhereIn() const;
|
||||
void rawWhereIn() const;
|
||||
void whereIn_ValueExpression() const;
|
||||
|
||||
void basicWhereNull() const;
|
||||
void basicWhereNotNull() const;
|
||||
void basicWhereNotNull_ColumnExpression() const;
|
||||
void whereNullWithVectorValue() const;
|
||||
void whereNotNullWithVectorValue() const;
|
||||
|
||||
@@ -742,6 +748,18 @@ void tst_PostgreSQL_QueryBuilder::basicOrWhere() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::basicOrWhere_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where(Raw("id"), ">", 4)
|
||||
.orWhereEq(Raw("\"name\""), "test3");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where id > ? or \"name\" = ?");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4), QVariant("test3")}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::orWhereWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -755,6 +773,20 @@ void tst_PostgreSQL_QueryBuilder::orWhereWithVectorValue() const
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::orWhereWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents")
|
||||
.where({{Raw("id"), 3}, {Raw("\"size\""), 10, ">"}})
|
||||
.orWhere({{Raw("progress"), 100, ">="}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where (id = ? and \"size\" > ?) or "
|
||||
"(progress >= ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::whereColumn() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -763,8 +795,9 @@ void tst_PostgreSQL_QueryBuilder::whereColumn() const
|
||||
.whereColumn("filepath", "=", "note")
|
||||
.whereColumn("size", ">=", "progress");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where \"filepath\" = \"note\" "
|
||||
"and \"size\" >= \"progress\"");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"filepath\" = \"note\" "
|
||||
"and \"size\" >= \"progress\"");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -778,8 +811,9 @@ void tst_PostgreSQL_QueryBuilder::orWhereColumn() const
|
||||
.whereColumnEq("filepath", "note")
|
||||
.orWhereColumnEq("size", "progress");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where \"filepath\" = \"note\" "
|
||||
"or \"size\" = \"progress\"");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"filepath\" = \"note\" "
|
||||
"or \"size\" = \"progress\"");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -791,13 +825,28 @@ void tst_PostgreSQL_QueryBuilder::orWhereColumn() const
|
||||
.whereColumnEq("filepath", "note")
|
||||
.orWhereColumn("size", ">", "progress");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where \"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\"");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\"");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::orWhereColumn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files")
|
||||
.whereColumnEq(Raw("filepath"), Raw("\"note\""))
|
||||
.orWhereColumn(Raw("size"), ">", Raw("progress"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where filepath = \"note\" "
|
||||
"or size > progress");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::whereColumnWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -807,8 +856,9 @@ void tst_PostgreSQL_QueryBuilder::whereColumnWithVectorValue() const
|
||||
.whereColumn({{"filepath", "note"},
|
||||
{"size", "progress", ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where (\"filepath\" = \"note\" "
|
||||
"and \"size\" > \"progress\")");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where (\"filepath\" = \"note\" "
|
||||
"and \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -820,8 +870,9 @@ void tst_PostgreSQL_QueryBuilder::whereColumnWithVectorValue() const
|
||||
.whereColumn({{"filepath", "note"},
|
||||
{"size", "progress", ">", "or"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -837,7 +888,8 @@ void tst_PostgreSQL_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" or \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
@@ -850,7 +902,8 @@ void tst_PostgreSQL_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">", "and"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" and \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"and \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
@@ -863,12 +916,27 @@ void tst_PostgreSQL_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">", "or"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" or \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::orWhereColumnWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files").whereEq("id", 2)
|
||||
.orWhereColumn({{Raw("filepath"), Raw("\"note\"")},
|
||||
{"size", Raw("progress"), ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (filepath = \"note\" or \"size\" > progress)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::basicWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -889,7 +957,8 @@ void tst_PostgreSQL_QueryBuilder::basicWhereIn() const
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or \"id\" in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,12 +980,26 @@ void tst_PostgreSQL_QueryBuilder::basicWhereNotIn() const
|
||||
builder->select("*").from("torrents").where("id", "=", 1)
|
||||
.orWhereNotIn("id", {2, 3, 4});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or \"id\" not in (?, ?, ?)");
|
||||
"select * from \"torrents\" where \"id\" = ? "
|
||||
"or \"id\" not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::basicWhereNotIn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where("id", "=", 1)
|
||||
.orWhereNotIn(Raw("id"), {2, 3, 4});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or id not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::emptyWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -965,7 +1048,7 @@ void tst_PostgreSQL_QueryBuilder::emptyNotWhereIn() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::rawWhereIn() const
|
||||
void tst_PostgreSQL_QueryBuilder::whereIn_ValueExpression() const
|
||||
{
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -1017,7 +1100,8 @@ void tst_PostgreSQL_QueryBuilder::basicWhereNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1028,7 +1112,8 @@ void tst_PostgreSQL_QueryBuilder::basicWhereNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
@@ -1052,7 +1137,8 @@ void tst_PostgreSQL_QueryBuilder::basicWhereNotNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNotNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1063,12 +1149,25 @@ void tst_PostgreSQL_QueryBuilder::basicWhereNotNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::basicWhereNotNull_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull(Raw("seeds"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or seeds is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
|
||||
void tst_PostgreSQL_QueryBuilder::whereNullWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -1088,8 +1187,9 @@ void tst_PostgreSQL_QueryBuilder::whereNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is null "
|
||||
"and \"total_seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is null "
|
||||
"and \"total_seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1100,8 +1200,9 @@ void tst_PostgreSQL_QueryBuilder::whereNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is null "
|
||||
"or \"total_seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is null "
|
||||
"or \"total_seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
@@ -1112,7 +1213,8 @@ void tst_PostgreSQL_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds", "total_seeds"});
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds",
|
||||
"total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
@@ -1126,8 +1228,9 @@ void tst_PostgreSQL_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNotNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1138,8 +1241,9 @@ void tst_PostgreSQL_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is not null "
|
||||
"or \"total_seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is not null "
|
||||
"or \"total_seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
|
||||
@@ -52,21 +52,27 @@ private slots:
|
||||
void whereWithVectorValue() const;
|
||||
|
||||
void basicOrWhere() const;
|
||||
void basicOrWhere_ColumnExpression() const;
|
||||
void orWhereWithVectorValue() const;
|
||||
void orWhereWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void whereColumn() const;
|
||||
void orWhereColumn() const;
|
||||
void orWhereColumn_ColumnExpression() const;
|
||||
void whereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue() const;
|
||||
void orWhereColumnWithVectorValue_ColumnExpression() const;
|
||||
|
||||
void basicWhereIn() const;
|
||||
void basicWhereNotIn() const;
|
||||
void basicWhereNotIn_ColumnExpression() const;
|
||||
void emptyWhereIn() const;
|
||||
void emptyNotWhereIn() const;
|
||||
void rawWhereIn() const;
|
||||
void whereIn_ValueExpression() const;
|
||||
|
||||
void basicWhereNull() const;
|
||||
void basicWhereNotNull() const;
|
||||
void basicWhereNotNull_ColumnExpression() const;
|
||||
void whereNullWithVectorValue() const;
|
||||
void whereNotNullWithVectorValue() const;
|
||||
|
||||
@@ -700,6 +706,18 @@ void tst_SQLite_QueryBuilder::basicOrWhere() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::basicOrWhere_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where(Raw("id"), ">", 4)
|
||||
.orWhereEq(Raw("\"name\""), "test3");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where id > ? or \"name\" = ?");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4), QVariant("test3")}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::orWhereWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -713,6 +731,20 @@ void tst_SQLite_QueryBuilder::orWhereWithVectorValue() const
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::orWhereWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents")
|
||||
.where({{Raw("id"), 3}, {Raw("\"size\""), 10, ">"}})
|
||||
.orWhere({{Raw("progress"), 100, ">="}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where (id = ? and \"size\" > ?) or "
|
||||
"(progress >= ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3), QVariant(10), QVariant(100)}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::whereColumn() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -736,8 +768,8 @@ void tst_SQLite_QueryBuilder::orWhereColumn() const
|
||||
.whereColumnEq("filepath", "note")
|
||||
.orWhereColumnEq("size", "progress");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where \"filepath\" = \"note\" "
|
||||
"or \"size\" = \"progress\"");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"filepath\" = \"note\" or \"size\" = \"progress\"");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -749,13 +781,27 @@ void tst_SQLite_QueryBuilder::orWhereColumn() const
|
||||
.whereColumnEq("filepath", "note")
|
||||
.orWhereColumn("size", ">", "progress");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where \"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\"");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"filepath\" = \"note\" or \"size\" > \"progress\"");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::orWhereColumn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files")
|
||||
.whereColumnEq(Raw("filepath"), Raw("\"note\""))
|
||||
.orWhereColumn(Raw("size"), ">", Raw("progress"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where filepath = \"note\" "
|
||||
"or size > progress");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::whereColumnWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -765,8 +811,8 @@ void tst_SQLite_QueryBuilder::whereColumnWithVectorValue() const
|
||||
.whereColumn({{"filepath", "note"},
|
||||
{"size", "progress", ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where (\"filepath\" = \"note\" "
|
||||
"and \"size\" > \"progress\")");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where (\"filepath\" = \"note\" and \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -778,8 +824,8 @@ void tst_SQLite_QueryBuilder::whereColumnWithVectorValue() const
|
||||
.whereColumn({{"filepath", "note"},
|
||||
{"size", "progress", ">", "or"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" where (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where (\"filepath\" = \"note\" or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>());
|
||||
}
|
||||
@@ -795,7 +841,8 @@ void tst_SQLite_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" or \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
@@ -808,7 +855,8 @@ void tst_SQLite_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">", "and"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" and \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"and \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
@@ -821,12 +869,27 @@ void tst_SQLite_QueryBuilder::orWhereColumnWithVectorValue() const
|
||||
{"size", "progress", ">", "or"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" or \"size\" > \"progress\")");
|
||||
"where \"id\" = ? or (\"filepath\" = \"note\" "
|
||||
"or \"size\" > \"progress\")");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::orWhereColumnWithVectorValue_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_previewable_files").whereEq("id", 2)
|
||||
.orWhereColumn({{Raw("filepath"), Raw("\"note\"")},
|
||||
{"size", Raw("progress"), ">"}});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_previewable_files\" "
|
||||
"where \"id\" = ? or (filepath = \"note\" or \"size\" > progress)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(2)}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::basicWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -847,7 +910,8 @@ void tst_SQLite_QueryBuilder::basicWhereIn() const
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or \"id\" in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,12 +933,26 @@ void tst_SQLite_QueryBuilder::basicWhereNotIn() const
|
||||
builder->select("*").from("torrents").where("id", "=", 1)
|
||||
.orWhereNotIn("id", {2, 3, 4});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or \"id\" not in (?, ?, ?)");
|
||||
"select * from \"torrents\" "
|
||||
"where \"id\" = ? or \"id\" not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
QVector<QVariant>({QVariant(1), QVariant(2),
|
||||
QVariant(3), QVariant(4)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::basicWhereNotIn_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrents").where("id", "=", 1)
|
||||
.orWhereNotIn(Raw("id"), {2, 3, 4});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrents\" where \"id\" = ? or id not in (?, ?, ?)");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(1), QVariant(2), QVariant(3), QVariant(4)}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::emptyWhereIn() const
|
||||
{
|
||||
{
|
||||
@@ -923,7 +1001,7 @@ void tst_SQLite_QueryBuilder::emptyNotWhereIn() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::rawWhereIn() const
|
||||
void tst_SQLite_QueryBuilder::whereIn_ValueExpression() const
|
||||
{
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
@@ -975,7 +1053,8 @@ void tst_SQLite_QueryBuilder::basicWhereNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -986,7 +1065,8 @@ void tst_SQLite_QueryBuilder::basicWhereNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
@@ -1010,7 +1090,8 @@ void tst_SQLite_QueryBuilder::basicWhereNotNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNotNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1021,12 +1102,25 @@ void tst_SQLite_QueryBuilder::basicWhereNotNull() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull("seeds");
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::basicWhereNotNull_ColumnExpression() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull(Raw("seeds"));
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or seeds is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
|
||||
void tst_SQLite_QueryBuilder::whereNullWithVectorValue() const
|
||||
{
|
||||
{
|
||||
@@ -1046,8 +1140,9 @@ void tst_SQLite_QueryBuilder::whereNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is null "
|
||||
"and \"total_seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is null "
|
||||
"and \"total_seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1058,8 +1153,9 @@ void tst_SQLite_QueryBuilder::whereNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is null "
|
||||
"or \"total_seeds\" is null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is null "
|
||||
"or \"total_seeds\" is null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
@@ -1070,7 +1166,8 @@ void tst_SQLite_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
{
|
||||
auto builder = createQuery(m_connection);
|
||||
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds", "total_seeds"});
|
||||
builder->select("*").from("torrent_peers").whereNotNull({"seeds",
|
||||
"total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
@@ -1084,8 +1181,9 @@ void tst_SQLite_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 4)
|
||||
.whereNotNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? and \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? and \"seeds\" is not null "
|
||||
"and \"total_seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(4)}));
|
||||
}
|
||||
@@ -1096,8 +1194,9 @@ void tst_SQLite_QueryBuilder::whereNotNullWithVectorValue() const
|
||||
builder->select("*").from("torrent_peers").whereEq("id", 3)
|
||||
.orWhereNotNull({"seeds", "total_seeds"});
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select * from \"torrent_peers\" where \"id\" = ? or \"seeds\" is not null "
|
||||
"or \"total_seeds\" is not null");
|
||||
"select * from \"torrent_peers\" "
|
||||
"where \"id\" = ? or \"seeds\" is not null "
|
||||
"or \"total_seeds\" is not null");
|
||||
QCOMPARE(builder->getBindings(),
|
||||
QVector<QVariant>({QVariant(3)}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user