elixir-sqlite / ecto_sqlite3

An Ecto SQLite3 adapter.
https://hexdocs.pm/ecto_sqlite3
MIT License
293 stars 43 forks source link

Cannot use `values`: "SQLite3 does not support table prefixes" #138

Open dlindenkreuz opened 10 months ago

dlindenkreuz commented 10 months ago

I am trying to use the values/2 macro to filter results by matching compound keys (group_name, name).

vals =
  Enum.map(rows, fn row ->
    %{group_name: row.group_name, name: row.name}
  end)

Repo.all(
  from s in Symbol,
    join: v in values(vals, %{group_name: :string, name: :string}),
    on: [group_name: s.group_name, name: s.name],
)

With SQLite, this error is raised:

** (ArgumentError) SQLite3 does not support table prefixes
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1894: Ecto.Adapters.SQLite3.Connection.quote_table/2
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1573: Ecto.Adapters.SQLite3.Connection.create_name/3
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1553: Ecto.Adapters.SQLite3.Connection.create_names/4
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1554: Ecto.Adapters.SQLite3.Connection.create_names/4
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1548: Ecto.Adapters.SQLite3.Connection.create_names/2
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:174: Ecto.Adapters.SQLite3.Connection.all/2
    (ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3.ex:184: Ecto.Adapters.SQLite3.prepare/2
    (ecto 3.11.1) lib/ecto/query/planner.ex:182: Ecto.Query.Planner.query_without_cache/4
    (ecto 3.11.1) lib/ecto/query/planner.ex:152: Ecto.Query.Planner.query_prepare/6
    (ecto 3.11.1) lib/ecto/query/planner.ex:127: Ecto.Query.Planner.query_with_cache/8
    (ecto 3.11.1) lib/ecto/repo/queryable.ex:214: Ecto.Repo.Queryable.execute/4
    (ecto 3.11.1) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
    iex:6: (file)

I added a debug statement to ecto_sqlite3 to print the arguments of quote_table/2: [(ecto_sqlite3 0.13.0) lib/ecto/adapters/sqlite3/connection.ex:1893: Ecto.Adapters.SQLite3.Connection.quote_table/2] {prefix, name} #=> {[[group_name: :string, name: :string], 2], :values}

The prefix var contains the types keyword list from values invocation and 2 indicating the number of rows. Looks like this doesn't belong there?

warmwaffles commented 10 months ago

hmm that does seem wrong. I'll look into this.

warmwaffles commented 10 months ago

Can you provide an abbreviated schema for Symbol? I'm going to pull together a test to demonstrate the bug.

dlindenkreuz commented 10 months ago

Sure!

defmodule MyApp.Symbols.Symbol do
  use Ecto.Schema

  @primary_key false

  schema "symbol" do
    field :group_name, :string, primary_key: true
    field :name, :string, primary_key: true
  end
end
dlindenkreuz commented 7 months ago

@warmwaffles Did you get around to this? I didn't find a workaround on my end 😿

warmwaffles commented 7 months ago

I have not yet. I'll try to get to it soon.