Skip to content

Raise when trying to count a source #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2023
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
6 changes: 6 additions & 0 deletions lib/ecto/adapters/sqlite3/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,12 @@ defmodule Ecto.Adapters.SQLite3.Connection do

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

def expr({:count, _, [{:&, _, [_]}]}, _sources, query) do
raise Ecto.QueryError,
query: query,
message: "The argument to `count/1` must be a column in SQLite3"
end

def expr({:json_extract_path, _, [expr, path]}, sources, query) do
path =
Enum.map(path, fn
Expand Down
13 changes: 13 additions & 0 deletions test/ecto/adapters/sqlite3/connection/aggregates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ defmodule Ecto.Adapters.SQLite3.Connection.AggregatesTest do
assert ~s{SELECT count(s0."x") FROM "schema" AS s0} == all(query)
end

test "raises when counting a source" do
query =
Schema
|> select([r], count(r))
|> plan()

msg = ~r"The argument to `count/1` must be a column in SQLite3"

assert_raise Ecto.QueryError, msg, fn ->
all(query)
end
end

test "raises when trying to distinct count" do
assert_raise Ecto.QueryError, fn ->
Schema
Expand Down