ecto_sqlite3 icon indicating copy to clipboard operation
ecto_sqlite3 copied to clipboard

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

Open dlindenkreuz opened this issue 1 year ago • 5 comments

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?

dlindenkreuz avatar Dec 19 '23 11:12 dlindenkreuz