Skip to content

Commit 7bfc25b

Browse files
committed
Introduce assert_valid_join which checks for unsupported join syntax
This improves the error messages for `JOIN VALUES (...) AS` clauses which were being mistakenly tagged as a table prefixing issue. Now the user gets a more accurate message. It also puts all the join syntax checking into a single function which makes it a bit eaiser to reason about (e.g. that hints, values, etc. are not OK, but other join constructs are)
1 parent 8313b99 commit 7bfc25b

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,14 +1014,9 @@ defmodule Ecto.Adapters.SQLite3.Connection do
10141014
on: %QueryExpr{expr: expression},
10151015
qual: qual,
10161016
ix: ix,
1017-
source: source,
1018-
hints: hints
1019-
} ->
1020-
if hints != [] do
1021-
raise Ecto.QueryError,
1022-
query: query,
1023-
message: "join hints are not supported by SQLite3"
1024-
end
1017+
source: source
1018+
} = join ->
1019+
assert_valid_join(join, query)
10251020

10261021
{join, name} = get_source(query, sources, ix, source)
10271022

@@ -1035,6 +1030,20 @@ defmodule Ecto.Adapters.SQLite3.Connection do
10351030
end)
10361031
end
10371032

1033+
defp assert_valid_join(%JoinExpr{hints: hints}, query) when hints != [] do
1034+
raise Ecto.QueryError,
1035+
query: query,
1036+
message: "join hints are not supported by SQLite3"
1037+
end
1038+
1039+
defp assert_valid_join(%JoinExpr{source: {:values, _, _}}, query) do
1040+
raise Ecto.QueryError,
1041+
query: query,
1042+
message: "SQLite3 adapter does not support values lists"
1043+
end
1044+
1045+
defp assert_valid_join(_join_expr, _query), do: :ok
1046+
10381047
defp join_on(:cross, true, _sources, _query), do: []
10391048

10401049
defp join_on(_qual, expression, sources, query),

test/ecto/adapters/sqlite3/connection/join_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ defmodule Ecto.Adapters.SQLite3.Connection.JoinTest do
135135
end
136136
end
137137

138+
test "join with values is not supported" do
139+
assert_raise Ecto.QueryError, fn ->
140+
rows = [%{x: 1, y: 1}, %{x: 2, y: 2}]
141+
types = %{x: :integer, y: :integer}
142+
143+
Schema
144+
|> join(
145+
:inner,
146+
[p],
147+
q in values(rows, types),
148+
on: [x: p.x(), y: p.y()]
149+
)
150+
|> select([p, q], {p.id, q.x})
151+
|> plan()
152+
|> all()
153+
end
154+
end
155+
138156
test "join with fragment" do
139157
query =
140158
Schema

0 commit comments

Comments
 (0)