An Ecto SQLite3 adapter.
0

Configure Feed

Select the types of activity you want to include in your feed.

Report correct error for value lists in joins (#156)

Some SQL syntax does not pass a table prefix (atom or string)
In the case of `create_name`, then third param may be a string or atom
prefix ... and in those cases should be treated as a prefix.

However syntax such as `VALUES (...)` will pass in the values list
information as the third tuple. this was causing spurious exceptions
to be thrown, rather than creating the correct table name

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)

authored by

Aaron Seigo and committed by
GitHub
(Nov 20, 2024, 3:11 PM -0600) b81cd484 c32929c9

+40 -10
+22 -10
lib/ecto/adapters/sqlite3/connection.ex
··· 993 993 defp using_join(%{joins: joins} = query, _kind, prefix, sources) do 994 994 froms = 995 995 Enum.map_intersperse(joins, ", ", fn 996 - %JoinExpr{qual: _qual, ix: ix, source: source} -> 996 + %JoinExpr{qual: _qual, ix: ix, source: source} = join -> 997 + assert_valid_join(join, query) 997 998 {join, name} = get_source(query, sources, ix, source) 998 999 [join, " AS " | name] 999 1000 end) ··· 1014 1015 on: %QueryExpr{expr: expression}, 1015 1016 qual: qual, 1016 1017 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 1018 + source: source 1019 + } = join -> 1020 + assert_valid_join(join, query) 1025 1021 1026 1022 {join, name} = get_source(query, sources, ix, source) 1027 1023 ··· 1034 1030 ] 1035 1031 end) 1036 1032 end 1033 + 1034 + defp assert_valid_join(%JoinExpr{hints: hints}, query) when hints != [] do 1035 + raise Ecto.QueryError, 1036 + query: query, 1037 + message: "join hints are not supported by SQLite3" 1038 + end 1039 + 1040 + defp assert_valid_join(%JoinExpr{source: {:values, _, _}}, query) do 1041 + raise Ecto.QueryError, 1042 + query: query, 1043 + message: "SQLite3 adapter does not support values lists" 1044 + end 1045 + 1046 + defp assert_valid_join(_join_expr, _query), do: :ok 1037 1047 1038 1048 defp join_on(:cross, true, _sources, _query), do: [] 1039 1049 ··· 1909 1919 1910 1920 defp quote_table(nil, name), do: quote_entity(name) 1911 1921 1912 - defp quote_table(_prefix, _name) do 1922 + defp quote_table(prefix, _name) when is_atom(prefix) or is_binary(prefix) do 1913 1923 raise ArgumentError, "SQLite3 does not support table prefixes" 1914 1924 end 1925 + 1926 + defp quote_table(_, name), do: quote_entity(name) 1915 1927 1916 1928 defp quote_entity(val) when is_atom(val) do 1917 1929 quote_entity(Atom.to_string(val))
+18
test/ecto/adapters/sqlite3/connection/join_test.exs
··· 135 135 end 136 136 end 137 137 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 + 138 156 test "join with fragment" do 139 157 query = 140 158 Schema