Skip to content

Commit

Permalink
added where column/value expression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 1, 2022
1 parent e0ae463 commit c3e4116
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/supported-compilers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords: [c++ orm, supported compilers, supported build systems, tinyorm]

# Supported Compilers

Following compilers are backed up by the GitHub Action [workflows](https://github.com/silverqx/TinyORM/tree/main/.github/workflows) (CI pipelines), these workflows also include more then __1264 unit tests__ 😮💥.
Following compilers are backed up by the GitHub Action [workflows](https://github.com/silverqx/TinyORM/tree/main/.github/workflows) (CI pipelines), these workflows also include more then __1270 unit tests__ 😮💥.

<div id="supported-compilers">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private Q_SLOTS:
void where_WithVectorValue_DefaultCondition() const;
void where_QueryableValue() const;
void where_QueryableColumn() const;
void where_ColumnExpression() const;
void where_ValueExpression() const;

void whereNot() const;
void whereNot_WithVectorValue() const;
Expand Down Expand Up @@ -1302,6 +1304,28 @@ void tst_MySql_QueryBuilder::where_QueryableColumn() const
}
}

void tst_MySql_QueryBuilder::where_ColumnExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(DB::raw(ID), "=", 3);
QCOMPARE(builder->toSql(),
"select * from `torrents` where id = ?");
QCOMPARE(builder->getBindings(),
QVector<QVariant> {QVariant(3)});
}

void tst_MySql_QueryBuilder::where_ValueExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(ID, "=", DB::raw(3))
.orWhereEq(DB::raw(NAME), DB::raw("'test3'"));
QCOMPARE(builder->toSql(),
"select * from `torrents` where `id` = 3 or name = 'test3'");
QVERIFY(builder->getBindings().isEmpty());
}

void tst_MySql_QueryBuilder::whereNot() const
{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ private Q_SLOTS:
void where() const;
void where_WithVectorValue() const;
void where_WithVectorValue_DefaultCondition() const;
void where_ColumnExpression() const;
void where_ValueExpression() const;

void whereNot() const;
void whereNot_WithVectorValue_DefaultCondition() const;
Expand Down Expand Up @@ -904,6 +906,28 @@ void tst_PostgreSQL_QueryBuilder::where_WithVectorValue_DefaultCondition() const
QVector<QVariant>({QVariant(100), QVariant(3), QVariant(10)}));
}

void tst_PostgreSQL_QueryBuilder::where_ColumnExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(DB::raw(ID), "=", 3);
QCOMPARE(builder->toSql(),
R"(select * from "torrents" where id = ?)");
QCOMPARE(builder->getBindings(),
QVector<QVariant> {QVariant(3)});
}

void tst_PostgreSQL_QueryBuilder::where_ValueExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(ID, "=", DB::raw(3))
.orWhereEq(DB::raw(NAME), DB::raw("'test3'"));
QCOMPARE(builder->toSql(),
R"(select * from "torrents" where "id" = 3 or name = 'test3')");
QVERIFY(builder->getBindings().isEmpty());
}

void tst_PostgreSQL_QueryBuilder::whereNot() const
{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ private Q_SLOTS:
void where() const;
void where_WithVectorValue() const;
void where_WithVectorValue_DefaultCondition() const;
void where_ColumnExpression() const;
void where_ValueExpression() const;

void whereNot() const;
void whereNot_WithVectorValue_DefaultCondition() const;
Expand Down Expand Up @@ -862,6 +864,28 @@ void tst_SQLite_QueryBuilder::where_WithVectorValue_DefaultCondition() const
QVector<QVariant>({QVariant(100), QVariant(3), QVariant(10)}));
}

void tst_SQLite_QueryBuilder::where_ColumnExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(DB::raw(ID), "=", 3);
QCOMPARE(builder->toSql(),
R"(select * from "torrents" where id = ?)");
QCOMPARE(builder->getBindings(),
QVector<QVariant> {QVariant(3)});
}

void tst_SQLite_QueryBuilder::where_ValueExpression() const
{
auto builder = createQuery();

builder->select("*").from("torrents").where(ID, "=", DB::raw(3))
.orWhereEq(DB::raw(NAME), DB::raw("'test3'"));
QCOMPARE(builder->toSql(),
R"(select * from "torrents" where "id" = 3 or name = 'test3')");
QVERIFY(builder->getBindings().isEmpty());
}

void tst_SQLite_QueryBuilder::whereNot() const
{
{
Expand Down

0 comments on commit c3e4116

Please sign in to comment.