Skip to content

Commit 794efcc

Browse files
raise when trying to count a source (#127)
1 parent 37b68d9 commit 794efcc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,12 @@ defmodule Ecto.Adapters.SQLite3.Connection do
13751375

13761376
def expr({:count, _, []}, _sources, _query), do: "count(*)"
13771377

1378+
def expr({:count, _, [{:&, _, [_]}]}, _sources, query) do
1379+
raise Ecto.QueryError,
1380+
query: query,
1381+
message: "The argument to `count/1` must be a column in SQLite3"
1382+
end
1383+
13781384
def expr({:json_extract_path, _, [expr, path]}, sources, query) do
13791385
path =
13801386
Enum.map(path, fn

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ defmodule Ecto.Adapters.SQLite3.Connection.AggregatesTest do
1515
assert ~s{SELECT count(s0."x") FROM "schema" AS s0} == all(query)
1616
end
1717

18+
test "raises when counting a source" do
19+
query =
20+
Schema
21+
|> select([r], count(r))
22+
|> plan()
23+
24+
msg = ~r"The argument to `count/1` must be a column in SQLite3"
25+
26+
assert_raise Ecto.QueryError, msg, fn ->
27+
all(query)
28+
end
29+
end
30+
1831
test "raises when trying to distinct count" do
1932
assert_raise Ecto.QueryError, fn ->
2033
Schema

0 commit comments

Comments
 (0)