elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
309 stars 112 forks source link

unused argument in parse function #71

Closed salisbury-espinosa closed 7 years ago

salisbury-espinosa commented 7 years ago

https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex#L991


  defp parse(call, query, params, opts) do
    try do
      DBConnection.Query.parse(query, opts)
    catch
      kind, reason ->
        pre_log(call, query, params, opts, kind, reason, System.stacktrace())
    end
  end

DBConnection.Query.parse - this function does not use the option params

so the code is not working:

q = "copy (SELECT timestamp,open,high,low,volume FROM ohlcv
          WHERE  interval=$1
          ORDER BY timestamp DESC) To STDOUT With CSV"
    {:ok, res} = Ecto.Adapters.SQL.query(Repo, q, [ interval_sec])

raise error:

** (ArgumentError) parameters must be of length 0 for query %Postgrex.Query{columns: nil, name: "", param_formats: [], param_oids: [], param_types: [], ref: #Reference<0.0.1.267>, result_formats: [], result_oids: nil, result_types: nil, statement: "copy (SELECT timestamp,open,high,low,volume FROM ohlcv\n          WHERE interval=$1\n          ORDER BY timestamp DESC) To STDOUT With CSV", types: {Ecto.Adapters.Postgres.TypeModule, 438313}}
    (postgrex) lib/postgrex/query.ex:50: DBConnection.Query.Postgrex.Query.encode/3
    (db_connection) lib/db_connection.ex:1073: DBConnection.describe_run/5
    (db_connection) lib/db_connection.ex:1144: anonymous fn/4 in DBConnection.run_meter/5
    (db_connection) lib/db_connection.ex:1201: DBConnection.run_begin/3
    (db_connection) lib/db_connection.ex:586: DBConnection.prepare_execute/4
    (ecto) lib/ecto/adapters/postgres/connection.ex:93: Ecto.Adapters.Postgres.Connection.execute/4
    (ecto) lib/ecto/adapters/sql.ex:243: Ecto.Adapters.SQL.sql_call/6
    lib/mix/tasks/trading.calculate_indicators.ex:22: Mix.Tasks.Trading.CalculateIndicators.run/1
    (mix) lib/mix/task.ex:296: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
    (elixir) lib/code.ex:363: Code.require_file/2
fishcakez commented 7 years ago

@salisbury-espinosa the DBConnection code is correct. There is a gotcha with COPY queries that can't use parameters IIRC.