From a5121fb84d404531302dbe91e4a267d4660908e0 Mon Sep 17 00:00:00 2001
From: Daniel Kukula <daniel.kuku@gmail.com>
Date: Sun, 13 Oct 2024 13:24:06 +0200
Subject: [PATCH] set postgrex_prepare in query

---
 lib/postgrex.ex          | 3 +++
 lib/postgrex/protocol.ex | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/postgrex.ex b/lib/postgrex.ex
index 0e73447d..845f947d 100644
--- a/lib/postgrex.ex
+++ b/lib/postgrex.ex
@@ -289,6 +289,9 @@ 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)}
 
diff --git a/lib/postgrex/protocol.ex b/lib/postgrex/protocol.ex
index b98d3e81..6aa18795 100644
--- a/lib/postgrex/protocol.ex
+++ b/lib/postgrex/protocol.ex
@@ -371,11 +371,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