Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,11 @@ if Code.ensure_loaded?(MyXQL) do
intersperse_map(fields, ", ", fn
{:&, _, [idx]} ->
case elem(sources, idx) do
{nil, source, nil} ->
error!(query, "MySQL adapter does not support selecting all fields from fragment #{source}. " <>
"Please specify exactly which fields you want to select")
{source, _, nil} ->
error!(query, "MySQL does not support selecting all fields from #{source} without a schema. " <>
error!(query, "MySQL adapter does not support selecting all fields from #{source} without a schema. " <>
"Please specify a schema or specify exactly which fields you want to select")
{_, source, _} ->
source
Expand Down
5 changes: 4 additions & 1 deletion lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ if Code.ensure_loaded?(Postgrex) do
intersperse_map(fields, ", ", fn
{:&, _, [idx]} ->
case elem(sources, idx) do
{nil, source, nil} ->
error!(query, "PostgreSQL adapter does not support selecting all fields from fragment #{source}. " <>
"Please specify exactly which fields you want to select")
{source, _, nil} ->
error!(query, "PostgreSQL does not support selecting all fields from #{source} without a schema. " <>
error!(query, "PostgreSQL adapter does not support selecting all fields from #{source} without a schema. " <>
"Please specify a schema or specify exactly which fields you want to select")
{_, source, _} ->
source
Expand Down
11 changes: 6 additions & 5 deletions lib/ecto/adapters/tds/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,13 @@ if Code.ensure_loaded?(Tds) do
intersperse_map(fields, ", ", fn
{:&, _, [idx]} ->
case elem(sources, idx) do
{nil, source, nil} ->
error!(query, "Tds adapter does not support selecting all fields from fragment #{source}. " <>
"Please specify exactly which fields you want to select")

{source, _, nil} ->
error!(
query,
"Tds adapter does not support selecting all fields from #{source} without a schema. " <>
"Please specify a schema or specify exactly which fields you want in projection"
)
error!(query, "Tds adapter does not support selecting all fields from #{source} without a schema. " <>
"Please specify a schema or specify exactly which fields you want in projection")

{_, source, _} ->
source
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule EctoSQL.MixProject do
if path = System.get_env("ECTO_PATH") do
{:ecto, path: path}
else
{:ecto, "~> 3.9.0-dev", github: "elixir-ecto/ecto"}
{:ecto, "~> 3.9.0-dev", github: "greg-rychlewski/ecto", branch: "fragment_source"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},
"deep_merge": {:hex, :deep_merge, "0.2.0", "c1050fa2edf4848b9f556fba1b75afc66608a4219659e3311d9c9427b5b680b3", [:mix], [], "hexpm", "e3bf435a54ed27b0ba3a01eb117ae017988804e136edcbe8a6a14c310daa966e"},
"earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"},
"ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "8831fe1fa8223c6db863559c41f68733eec301f6", []},
"ecto": {:git, "https://github.com/greg-rychlewski/ecto.git", "31e8cd4d54897eb138abc52b658f1705fa10d845", [branch: "fragment_source"]},
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
Expand Down
14 changes: 13 additions & 1 deletion test/ecto/adapters/myxql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Ecto.Adapters.MyXQLTest do
query = "0posts" |> select([:x]) |> plan()
assert all(query) == ~s{SELECT t0.`x` FROM `0posts` AS t0}

assert_raise Ecto.QueryError, ~r"MySQL does not support selecting all fields from `posts` without a schema", fn ->
assert_raise Ecto.QueryError, ~r"MySQL adapter does not support selecting all fields from `posts` without a schema", fn ->
all from(p in "posts", select: p) |> plan()
end
end
Expand All @@ -104,6 +104,18 @@ defmodule Ecto.Adapters.MyXQLTest do
assert all(query) == ~s{SELECT s0.`x`, s0.`z` FROM (SELECT ss0.`x` AS `x`, ss0.`z` AS `z` FROM (SELECT ssp0.`x` AS `x`, ssp0.`y` AS `z` FROM `posts` AS ssp0) AS ss0) AS s0}
end

test "from with fragment" do
query = from(f in fragment("select ? as x", ^"abc"), select: f.x) |> plan()
assert all(query) == ~s{SELECT f0.`x` FROM (select ? as x) AS f0}

query = from(fragment("select ? as x", ^"abc"), select: fragment("x")) |> plan()
assert all(query) == ~s{SELECT x FROM (select ? as x) AS f0}

assert_raise Ecto.QueryError, ~r"MySQL adapter does not support selecting all fields from fragment", fn ->
all from(f in fragment("select ? as x", ^"abc"), select: f) |> plan()
end
end

test "CTE" do
initial_query =
"categories"
Expand Down
14 changes: 13 additions & 1 deletion test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule Ecto.Adapters.PostgresTest do
query = "0posts" |> select([:x]) |> plan()
assert all(query) == ~s{SELECT t0."x" FROM "0posts" AS t0}

assert_raise Ecto.QueryError, ~r"PostgreSQL does not support selecting all fields from \"posts\" without a schema", fn ->
assert_raise Ecto.QueryError, ~r"PostgreSQL adapter does not support selecting all fields from \"posts\" without a schema", fn ->
all from(p in "posts", select: p) |> plan()
end
end
Expand All @@ -109,6 +109,18 @@ defmodule Ecto.Adapters.PostgresTest do
assert all(query) == ~s{SELECT s0."x", s0."z" FROM (SELECT ss0."x" AS "x", ss0."z" AS "z" FROM (SELECT ssp0."x" AS "x", ssp0."y" AS "z" FROM "posts" AS ssp0) AS ss0) AS s0}
end

test "from with fragment" do
query = from(f in fragment("select ? as x", ^"abc"), select: f.x) |> plan()
assert all(query) == ~s{SELECT f0."x" FROM (select $1 as x) AS f0}

query = from(fragment("select ? as x", ^"abc"), select: fragment("x")) |> plan()
assert all(query) == ~s{SELECT x FROM (select $1 as x) AS f0}

assert_raise Ecto.QueryError, ~r"PostgreSQL adapter does not support selecting all fields from fragment", fn ->
all from(f in fragment("select ? as x", ^"abc"), select: f) |> plan()
end
end

test "CTE" do
initial_query =
"categories"
Expand Down
12 changes: 12 additions & 0 deletions test/ecto/adapters/tds_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ defmodule Ecto.Adapters.TdsTest do
~s{SELECT s0.[x], s0.[z] FROM (SELECT ss0.[x] AS [x], ss0.[z] AS [z] FROM (SELECT ssp0.[x] AS [x], ssp0.[y] AS [z] FROM [posts] AS ssp0) AS ss0) AS s0}
end

test "from with fragment" do
query = from(f in fragment("select ? as x", ^"abc"), select: f.x) |> plan()
assert all(query) == ~s{SELECT f0.[x] FROM (select @1 as x) AS f0}

query = from(fragment("select ? as x", ^"abc"), select: fragment("x")) |> plan()
assert all(query) == ~s{SELECT x FROM (select @1 as x) AS f0}

assert_raise Ecto.QueryError, ~r"Tds adapter does not support selecting all fields from fragment", fn ->
all from(f in fragment("select ? as x", ^"abc"), select: f) |> plan()
end
end

test "join with subquery" do
posts = subquery("posts" |> where(title: ^"hello") |> select([r], %{x: r.x, y: r.y}))

Expand Down