diff --git a/lib/postgrex.ex b/lib/postgrex.ex index 845f947d..8f53b5ba 100644 --- a/lib/postgrex.ex +++ b/lib/postgrex.ex @@ -289,9 +289,6 @@ defmodule Postgrex do @spec query(conn, iodata, list, [execute_option]) :: {:ok, Postgrex.Result.t()} | {:error, Exception.t()} def query(conn, statement, params, opts \\ []) do - prepare? = !Keyword.get(opts, :comment) - opts = Keyword.put(opts, :postgrex_prepare, prepare?) - if name = Keyword.get(opts, :cache_statement) do query = %Query{name: name, cache: :statement, statement: IO.iodata_to_binary(statement)} @@ -366,7 +363,7 @@ defmodule Postgrex do {:ok, Postgrex.Query.t()} | {:error, Exception.t()} def prepare(conn, name, statement, opts \\ []) do query = %Query{name: name, statement: statement} - prepare? = !Keyword.get(opts, :comment) + prepare? = Keyword.get(opts, :comment) == nil opts = Keyword.put(opts, :postgrex_prepare, prepare?) DBConnection.prepare(conn, query, opts) end @@ -377,7 +374,7 @@ defmodule Postgrex do """ @spec prepare!(conn, iodata, iodata, [option]) :: Postgrex.Query.t() def prepare!(conn, name, statement, opts \\ []) do - prepare? = !Keyword.get(opts, :comment) + prepare? = Keyword.get(opts, :comment) == nil opts = Keyword.put(opts, :postgrex_prepare, prepare?) DBConnection.prepare!(conn, %Query{name: name, statement: statement}, opts) end diff --git a/lib/postgrex/protocol.ex b/lib/postgrex/protocol.ex index 6aa18795..e2628ea5 100644 --- a/lib/postgrex/protocol.ex +++ b/lib/postgrex/protocol.ex @@ -346,19 +346,21 @@ defmodule Postgrex.Protocol do end def handle_prepare(%Query{name: ""} = query, opts, s) do - prepare? = Keyword.get(opts, :postgrex_prepare, false) - status = new_status(opts, prepare: prepare?) + prepare = Keyword.get(opts, :postgrex_prepare, false) + status = new_status(opts, prepare: prepare) - if prepare? do - parse_describe_close(s, status, query) - else - comment = Keyword.get(opts, :comment) + case prepare do + true -> + parse_describe_close(s, status, query) - if is_binary(comment) && String.contains?(comment, "*/") do - raise @comment_validation_error - else - parse_describe_flush(s, status, query, comment) - end + false -> + comment = Keyword.get(opts, :comment) + + if is_binary(comment) && String.contains?(comment, "*/") do + raise @comment_validation_error + else + parse_describe_flush(s, status, query, comment) + end end end @@ -371,11 +373,11 @@ defmodule Postgrex.Protocol do if new_query = cached_query(s, query) do {:ok, new_query, s} else - prepare? = Keyword.get(opts, :postgrex_prepare, false) - status = new_status(opts, prepare: prepare?) + prepare = Keyword.get(opts, :postgrex_prepare, false) + status = new_status(opts, prepare: prepare) result = - case prepare? do + case prepare do true -> close_parse_describe(s, status, query) false -> close_parse_describe_flush(s, status, query) end @@ -1605,7 +1607,7 @@ defmodule Postgrex.Protocol do end defp parse_describe_comment_msgs(query, comment, tail) when is_binary(comment) do - statement = query.statement <> "/* #{comment} */" + statement = query.statement <> "/*#{comment}*/" query = %{query | statement: statement} parse_describe_msgs(query, tail) end @@ -3392,7 +3394,6 @@ defmodule Postgrex.Protocol do defp msg_send(s, msgs, buffer) when is_list(msgs) do binaries = Enum.reduce(msgs, [], &[&2 | maybe_encode_msg(&1)]) - do_send(s, binaries, buffer) end