pgfe icon indicating copy to clipboard operation
pgfe copied to clipboard

Removing comments when calling conn.execute()

Open stan-yu opened this issue 1 month ago • 2 comments

Hi,

there is such a code example:

pgfe::Connection conn(pgfe::Connection_options{}.set(pgfe::Communication_mode::net).set_hostname( ...)....;
pgfe::Transaction_guard tg{*conn_};
conn.call("public.get_objects", start_of_interval, end_of_interval, "cr");
conn.execute([](pgfe::Row&& row) { std::cout << pgfe::to<std::string>(row[0]) << std::endl ; },
               "fetch /* pass my comment */ all from cr");
tg.commit();

In conn.execute() call, I want to pass comments to the server. In this case, the comments are multiline(but it doesn't matter, oneline one is removed too). But the library removes them forcibly. If you follow the call chain, this happens in pgfe/src/pgfe/statement.cpp in the Statement::to_query_string() function:

for (const auto& fragment : fragments_) {
    switch (fragment.type) {
    case Ft::text:
      result += fragment.str;
      break;
    case Ft::one_line_comment:
      [[fallthrough]];
    case Ft::multi_line_comment:
      break;
...

Is it possible to somehow control this behavior or use other methods of calling FETCH so that comments are passed to server? pgfe version 2.2.3

Thanks.

stan-yu avatar Dec 05 '25 14:12 stan-yu

Hello,

While it'll be possible in the upcoming version 3 (which I hope to release this or next month), I'm really curious, why do you need to send comments to a server?

dmitigr avatar Dec 06 '25 08:12 dmitigr

Administrators monitor load and other parameters, but there are many different stored procedures being called from different clients, and they need to see the name of the called procedure in the logs. In our case, to track which specific stored procedure FETCH ALL is associated with. For some reason, the server logs contain entries like this: FETCH ALL FROM "<unnamed portal 4>"

Other clients from other libraries (for example, .NET) insert comments before FETCH. As a result, the logs will show entries like this with the procedure name and package: /* public.get_objects */FETCH ALL FROM "<unnamed portal 4>"

Thanks for the information about the new version, we'll be waiting!

stan-yu avatar Dec 08 '25 10:12 stan-yu