@@ -347,8 +347,12 @@ defmodule Postgrex.Protocol do
347
347
status = new_status ( opts , prepare: prepare )
348
348
349
349
case prepare do
350
- true -> parse_describe_close ( s , status , query )
351
- false -> parse_describe_flush ( s , status , query )
350
+ true ->
351
+ parse_describe_close ( s , status , query )
352
+
353
+ false ->
354
+ comment = Keyword . get ( opts , :comment )
355
+ parse_describe_flush ( s , status , query , comment )
352
356
end
353
357
end
354
358
@@ -1418,9 +1422,9 @@ defmodule Postgrex.Protocol do
1418
1422
parse_describe ( s , status , query )
1419
1423
end
1420
1424
1421
- defp parse_describe_flush ( s , % { mode: :transaction } = status , query ) do
1425
+ defp parse_describe_flush ( s , % { mode: :transaction } = status , query , comment ) do
1422
1426
% { buffer: buffer } = s
1423
- msgs = parse_describe_msgs ( query , [ msg_flush ( ) ] )
1427
+ msgs = parse_describe_comment_msgs ( query , comment , [ msg_flush ( ) ] )
1424
1428
1425
1429
with :ok <- msg_send ( % { s | buffer: nil } , msgs , buffer ) ,
1426
1430
{ :ok , % Query { ref: ref } = query , % { postgres: postgres } = s , buffer } <-
@@ -1442,11 +1446,12 @@ defmodule Postgrex.Protocol do
1442
1446
defp parse_describe_flush (
1443
1447
% { postgres: :transaction , buffer: buffer } = s ,
1444
1448
% { mode: :savepoint } = status ,
1445
- query
1449
+ query ,
1450
+ comment
1446
1451
) do
1447
1452
msgs =
1448
1453
[ msg_query ( statement: "SAVEPOINT postgrex_query" ) ] ++
1449
- parse_describe_msgs ( query , [ msg_flush ( ) ] )
1454
+ parse_describe_comment_msgs ( query , comment , [ msg_flush ( ) ] )
1450
1455
1451
1456
with :ok <- msg_send ( % { s | buffer: nil } , msgs , buffer ) ,
1452
1457
{ :ok , _ , % { buffer: buffer } = s } <- recv_transaction ( s , status , buffer ) ,
@@ -1466,7 +1471,7 @@ defmodule Postgrex.Protocol do
1466
1471
end
1467
1472
end
1468
1473
1469
- defp parse_describe_flush ( % { postgres: postgres } = s , % { mode: :savepoint } , _ )
1474
+ defp parse_describe_flush ( % { postgres: postgres } = s , % { mode: :savepoint } , _ , _ )
1470
1475
when postgres in [ :idle , :error ] do
1471
1476
transaction_error ( s , postgres )
1472
1477
end
@@ -1593,6 +1598,16 @@ defmodule Postgrex.Protocol do
1593
1598
transaction_error ( s , postgres )
1594
1599
end
1595
1600
1601
+ defp parse_describe_comment_msgs ( query , comment , tail ) when is_binary ( comment ) do
1602
+ statement = [ query . statement , "/*" , comment , "*/" ]
1603
+ query = % { query | statement: statement }
1604
+ parse_describe_msgs ( query , tail )
1605
+ end
1606
+
1607
+ defp parse_describe_comment_msgs ( query , _comment , tail ) do
1608
+ parse_describe_msgs ( query , tail )
1609
+ end
1610
+
1596
1611
defp parse_describe_msgs ( query , tail ) do
1597
1612
% Query { name: name , statement: statement , param_oids: param_oids } = query
1598
1613
type_oids = param_oids || [ ]
@@ -2079,7 +2094,7 @@ defmodule Postgrex.Protocol do
2079
2094
2080
2095
_ ->
2081
2096
# flush awaiting execute or declare
2082
- parse_describe_flush ( s , status , query )
2097
+ parse_describe_flush ( s , status , query , nil )
2083
2098
end
2084
2099
end
2085
2100
@@ -2105,7 +2120,7 @@ defmodule Postgrex.Protocol do
2105
2120
defp handle_prepare_execute ( % Query { name: "" } = query , params , opts , s ) do
2106
2121
status = new_status ( opts )
2107
2122
2108
- case parse_describe_flush ( s , status , query ) do
2123
+ case parse_describe_flush ( s , status , query , nil ) do
2109
2124
{ :ok , query , s } ->
2110
2125
bind_execute_close ( s , status , query , params )
2111
2126
@@ -2396,7 +2411,7 @@ defmodule Postgrex.Protocol do
2396
2411
defp handle_prepare_bind ( % Query { name: "" } = query , params , res , opts , s ) do
2397
2412
status = new_status ( opts )
2398
2413
2399
- case parse_describe_flush ( s , status , query ) do
2414
+ case parse_describe_flush ( s , status , query , nil ) do
2400
2415
{ :ok , query , s } ->
2401
2416
bind ( s , status , query , params , res )
2402
2417
0 commit comments