livehelpnow / tds_ecto

TDS Adapter for Ecto
57 stars 34 forks source link

How to do named parameterised queries ? #78

Closed ghost closed 2 months ago

ghost commented 3 years ago

Is it possible to do named parameterised queries using tds_ecto?

I can't find an example in the code, test or docs and can't figure out the code path. Have tried with various input combinations but this is what I ended on.

iex(77)>  Ecto.Adapters.SQL.query!(SyxDB.Repo, "SELECT @user", [ %Tds.Parameter{name: "@user", value: "m", type: :binary} ]  )           
** (ArgumentError) Tds adapter is unable to convert struct `Tds.Parameter` into supported MSSQL types
    (ecto_sql 3.5.4) lib/ecto/adapters/tds/connection.ex:1612: Ecto.Adapters.Tds.Connection.error!/2
    (ecto_sql 3.5.4) lib/ecto/adapters/tds/connection.ex:79: anonymous fn/2 in Ecto.Adapters.Tds.Connection.prepare_params/1
    (elixir 1.11.2) lib/enum.ex:1521: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (ecto_sql 3.5.4) lib/ecto/adapters/tds/connection.ex:78: Ecto.Adapters.Tds.Connection.prepare_params/1
    (ecto_sql 3.5.4) lib/ecto/adapters/tds/connection.ex:65: Ecto.Adapters.Tds.Connection.query/4
    (ecto_sql 3.5.4) lib/ecto/adapters/sql.ex:371: Ecto.Adapters.SQL.query!/4

If you can point me in the right direction, I'm happy to create a PR to add a test example or docs.