From 9ad0fc84a045eafd15974edf1eb6f690e85039bf Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Wed, 16 Oct 2024 19:10:58 -0400 Subject: [PATCH 1/3] add back parens --- lib/ecto/adapters/myxql/connection.ex | 2 +- test/ecto/adapters/myxql_test.exs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ecto/adapters/myxql/connection.ex b/lib/ecto/adapters/myxql/connection.ex index cc951c50..d1663638 100644 --- a/lib/ecto/adapters/myxql/connection.ex +++ b/lib/ecto/adapters/myxql/connection.ex @@ -826,7 +826,7 @@ if Code.ensure_loaded?(MyXQL) do fun, ?(, modifier, - Enum.map_intersperse(args, ", ", &top_level_expr(&1, sources, query)), + Enum.map_intersperse(args, ", ", &expr(&1, sources, query)), ?) ] end diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index c2d499d7..48466be3 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -478,7 +478,7 @@ defmodule Ecto.Adapters.MyXQLTest do |> plan() assert all(query) == - ~s{SELECT s0.`x` FROM `schema` AS s0 ORDER BY exists(SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`))} + ~s{SELECT s0.`x` FROM `schema` AS s0 ORDER BY exists((SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`)))} end test "union and union all" do @@ -882,7 +882,7 @@ defmodule Ecto.Adapters.MyXQLTest do |> plan() assert all(query) == - ~s{SELECT s0.`x` FROM `schema` AS s0 GROUP BY exists(SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`))} + ~s{SELECT s0.`x` FROM `schema` AS s0 GROUP BY exists((SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`)))} end test "interpolated values" do @@ -1089,7 +1089,7 @@ defmodule Ecto.Adapters.MyXQLTest do |> plan assert all(query) == - ~s{SELECT s0.`x` FROM `schema` AS s0 WINDOW `w` AS (ORDER BY exists(SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`)))} + ~s{SELECT s0.`x` FROM `schema` AS s0 WINDOW `w` AS (ORDER BY exists((SELECT ss0.`x` AS `result` FROM `schema` AS ss0 WHERE (ss0.`x` = s0.`x`))))} end test "two windows" do From dde27f492f157dd10a5acf6105b9fddaedf0ecaf Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Fri, 18 Oct 2024 09:53:32 -0400 Subject: [PATCH 2/3] add tests --- test/ecto/adapters/myxql_test.exs | 6 ++++++ test/ecto/adapters/postgres_test.exs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index 48466be3..edff7926 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -416,6 +416,12 @@ defmodule Ecto.Adapters.MyXQLTest do assert all(query) == ~s{SELECT coalesce(s0.`x`, 5) FROM `schema` AS s0} end + test "coalesce with subquery" do + squery = from s in Schema, select: s.x + query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() + assert all(query) == ~s{SELECT coalesce((SELECT ss0.`x` AS `x` FROM `schema` AS ss0), 5) FROM `schema` AS s0} + end + test "where" do query = Schema |> where([r], r.x == 42) |> where([r], r.y != 43) |> select([r], r.x) |> plan() diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 617f59ff..4bb0a2e4 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -584,6 +584,12 @@ defmodule Ecto.Adapters.PostgresTest do assert all(query) == ~s{SELECT coalesce(s0."x", 5) FROM "schema" AS s0} end + test "coalesce with subquery" do + squery = from s in Schema, select: s.x + query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() + assert all(query) == ~s{SELECT coalesce((SELECT ss0."x" AS "x" FROM "schema" AS ss0), 5) FROM "schema" AS s0} + end + test "where" do query = Schema |> where([r], r.x == 42) |> where([r], r.y != 43) |> select([r], r.x) |> plan() From a54cee01abb1862fb205ef63e57e4bc1062a2e13 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Fri, 18 Oct 2024 09:57:03 -0400 Subject: [PATCH 3/3] format --- test/ecto/adapters/myxql_test.exs | 4 +++- test/ecto/adapters/postgres_test.exs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index edff7926..ee02cbb4 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -419,7 +419,9 @@ defmodule Ecto.Adapters.MyXQLTest do test "coalesce with subquery" do squery = from s in Schema, select: s.x query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() - assert all(query) == ~s{SELECT coalesce((SELECT ss0.`x` AS `x` FROM `schema` AS ss0), 5) FROM `schema` AS s0} + + assert all(query) == + ~s{SELECT coalesce((SELECT ss0.`x` AS `x` FROM `schema` AS ss0), 5) FROM `schema` AS s0} end test "where" do diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 4bb0a2e4..e9a64cf5 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -587,7 +587,9 @@ defmodule Ecto.Adapters.PostgresTest do test "coalesce with subquery" do squery = from s in Schema, select: s.x query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() - assert all(query) == ~s{SELECT coalesce((SELECT ss0."x" AS "x" FROM "schema" AS ss0), 5) FROM "schema" AS s0} + + assert all(query) == + ~s{SELECT coalesce((SELECT ss0."x" AS "x" FROM "schema" AS ss0), 5) FROM "schema" AS s0} end test "where" do