diff --git a/lib/ecto/adapters/myxql/connection.ex b/lib/ecto/adapters/myxql/connection.ex index 386b5af7..e8da6c30 100644 --- a/lib/ecto/adapters/myxql/connection.ex +++ b/lib/ecto/adapters/myxql/connection.ex @@ -778,8 +778,8 @@ if Code.ensure_loaded?(MyXQL) do [to_string(literal)] end - defp expr({:splice, _, [{:^, _, [_, length]}]}, _sources, _query) do - Enum.intersperse(List.duplicate(??, length), ?,) + defp expr({:splice, _, splice_exprs}, sources, query) do + Enum.map_intersperse(splice_exprs, ",", &expr(&1, sources, query)) end defp expr({:selected_as, _, [name]}, _sources, _query) do diff --git a/lib/ecto/adapters/postgres/connection.ex b/lib/ecto/adapters/postgres/connection.ex index d8f063f7..c6ce7596 100644 --- a/lib/ecto/adapters/postgres/connection.ex +++ b/lib/ecto/adapters/postgres/connection.ex @@ -997,8 +997,8 @@ if Code.ensure_loaded?(Postgrex) do [to_string(literal)] end - defp expr({:splice, _, [{:^, _, [idx, length]}]}, _sources, _query) do - Enum.map_join(1..length, ",", &"$#{idx + &1}") + defp expr({:splice, _, splice_exprs}, sources, query) do + Enum.map_intersperse(splice_exprs, ",", &expr(&1, sources, query)) end defp expr({:selected_as, _, [name]}, _sources, _query) do diff --git a/lib/ecto/adapters/tds/connection.ex b/lib/ecto/adapters/tds/connection.ex index d2e18902..a0792983 100644 --- a/lib/ecto/adapters/tds/connection.ex +++ b/lib/ecto/adapters/tds/connection.ex @@ -838,8 +838,8 @@ if Code.ensure_loaded?(Tds) do [to_string(literal)] end - defp expr({:splice, _, [{:^, _, [idx, length]}]}, _sources, _query) do - list_param_to_args(idx, length) + defp expr({:splice, _, splice_exprs}, sources, query) do + Enum.map_intersperse(splice_exprs, ",", &expr(&1, sources, query)) end defp expr({:selected_as, _, [name]}, _sources, _query) do diff --git a/mix.exs b/mix.exs index 0013472e..20e72384 100644 --- a/mix.exs +++ b/mix.exs @@ -78,7 +78,7 @@ defmodule EctoSQL.MixProject do if path = System.get_env("ECTO_PATH") do {:ecto, path: path} else - {:ecto, git: "https://github.com/elixir-ecto/ecto.git", branch: "master"} + {:ecto, git: "https://github.com/greg-rychlewski/ecto.git", branch: "dynamic_splice"} end end diff --git a/mix.lock b/mix.lock index 270dcdd1..268f5f7a 100644 --- a/mix.lock +++ b/mix.lock @@ -6,7 +6,7 @@ "decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "3ab6a20b255fe2cee1fd9f6ae160c6fde772dce7", [branch: "master"]}, + "ecto": {:git, "https://github.com/greg-rychlewski/ecto.git", "13dfff3120fb5fb40bbb690c2699dfa6c73872e5", [branch: "dynamic_splice"]}, "ex_doc": {:hex, :ex_doc, "0.39.1", "e19d356a1ba1e8f8cfc79ce1c3f83884b6abfcb79329d435d4bbb3e97ccc286e", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "8abf0ed3e3ca87c0847dfc4168ceab5bedfe881692f1b7c45f4a11b232806865"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index 3aed445f..5779c60b 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -672,6 +672,13 @@ defmodule Ecto.Adapters.MyXQLTest do assert all(query) == ~s{SELECT s0.`x` FROM `schema` AS s0 WHERE (s0.`x` in (?,?,?,?,?))} + query = + Schema + |> select([_], fragment("concat_ws(?,?)", ".", splice(^["public", dynamic([r], r.x)]))) + |> plan() + + assert all(query) == ~s{SELECT concat_ws('.',?,s0.`x`) FROM `schema` AS s0} + value = 13 query = Schema |> select([r], fragment("lcase(?, ?)", r.x, ^value)) |> plan() assert all(query) == ~s{SELECT lcase(s0.`x`, ?) FROM `schema` AS s0} diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index cea992a3..1037e668 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -852,6 +852,13 @@ defmodule Ecto.Adapters.PostgresTest do assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE (s0."x" in ($1,$2,$3,$4,$5))} + query = + Schema + |> select([_], fragment("concat_ws(?,?)", ".", splice(^["public", dynamic([r], r.x)]))) + |> plan() + + assert all(query) == ~s{SELECT concat_ws('.',$1,s0."x") FROM "schema" AS s0} + value = 13 query = Schema |> select([r], fragment("downcase(?, ?)", r.x, ^value)) |> plan() assert all(query) == ~s{SELECT downcase(s0."x", $1) FROM "schema" AS s0} diff --git a/test/ecto/adapters/tds_test.exs b/test/ecto/adapters/tds_test.exs index 0c45630f..d669892d 100644 --- a/test/ecto/adapters/tds_test.exs +++ b/test/ecto/adapters/tds_test.exs @@ -708,6 +708,13 @@ defmodule Ecto.Adapters.TdsTest do assert all(query) == ~s{SELECT s0.[x] FROM [schema] AS s0 WHERE (s0.[x] in (@1,@2,@3,@4,@5))} + query = + Schema + |> select([_], fragment("concat_ws(?,?)", ".", splice(^["public", dynamic([r], r.x)]))) + |> plan() + + assert all(query) == ~s{SELECT concat_ws(N'.',@1,s0.[x]) FROM [schema] AS s0} + value = 13 query = Schema |> select([r], fragment("lower(?)", ^value)) |> plan() assert all(query) == ~s{SELECT lower(@1) FROM [schema] AS s0}