Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle PGRES_COMMAND_OK in pgresult_stream_any #447

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

jeremyevans
Copy link
Contributor

Fixes usage when trying to stream the result of a procedure
call that returns no results.

Fixes Sequel tests when Sequel is set to stream all results.
Here's a reproducer that just uses ruby-pg without Sequel:

require 'pg'
conn = PG::Connection.new(user: "sequel_test")
conn.exec(<<END)
CREATE TABLE posts (a INTEGER);
CREATE OR REPLACE PROCEDURE test_procedure_posts()
LANGUAGE SQL
AS $$
INSERT INTO posts VALUES (1) RETURNING *;
INSERT INTO posts VALUES (2) RETURNING *;
SELECT max(posts.a), min(posts.a) FROM posts;
$$;
END
at_exit{conn.exec("DROP PROCEDURE test_procedure_posts(); DROP TABLE posts;")}

conn.send_query("CALL test_procedure_posts();")
conn.set_single_row_mode
# Next method call fails without patch:
# no result received - possibly an intersection with another result retrieval (PG::NoResultError)
conn.get_result.stream_each do |res|
  p [__LINE__, res]
end
conn.block

conn.send_query("CALL test_procedure_posts();")
conn.set_single_row_mode
while res = conn.get_result
  p [__LINE__, res]
end
conn.block

Fixes usage when trying to stream the result of a procedure
call that returns no results.
@larskanis larskanis merged commit 22e1a10 into ged:master Mar 23, 2022
@larskanis
Copy link
Collaborator

Thanks for working on this! Although single_row_mode is not intended for this use case, the change makes sense for consistency.

Not only the CALL command is affected but also INSERT, CREATE etc. So my test case is a bit simpler: ee4bf3d

Do you need a release with this change?

@jeremyevans
Copy link
Contributor Author

It seems like a corner case, so I don't think we need a release right away. We can wait for the normal release schedule.

@larskanis
Copy link
Collaborator

OK, thank you for working together once again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants