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: 5 additions & 0 deletions lib/ecto/query/planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,11 @@ defmodule Ecto.Query.Planner do
{{:fragment, meta, fragments}, acc}
end

defp prewalk_source({{:fragment, meta, fragments}, schema}, kind, query, expr, acc, adapter) do
{fragments, acc} = prewalk(fragments, kind, query, expr, acc, adapter)
{{{:fragment, meta, fragments}, schema}, acc}
end

defp prewalk_source({:values, meta, [types, num_rows]}, _kind, _query, _expr, acc, _adapter) do
length = num_rows * length(types)
# Adapters will use the schema types to cast the values
Expand Down
20 changes: 20 additions & 0 deletions test/ecto/query/planner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,26 @@ defmodule Ecto.Query.PlannerTest do
] = cache_key
end

test "plan: tuple source with fragment numbers later placeholders after the source" do
good_query =
from(f in fragment("some_sql_function(?)", ^"value"),
where: f.visits in ^[1, 2],
select: f
)
|> normalize()

assert Macro.to_string(hd(good_query.wheres).expr) == "&0.visits() in ^(1, 2)"

bad_query =
from(f in {fragment("some_sql_function(?)", ^"value"), Post},
where: f.visits in ^[1, 2],
select: f
)
|> normalize()

assert Macro.to_string(hd(bad_query.wheres).expr) == "&0.visits() in ^(1, 2)"
end

describe "plan: CTEs" do
test "with uncacheable queries are uncacheable" do
{_, _, _, cache} =
Expand Down
Loading