提交 112977cb 编写于 作者: E eileencodes

Support cursors on readonly queries

This adds `:declare`, `:fetch`, `:move`, and `:close` to allowed queries
when `while_preventing_writes` is set. I didn't support `:open` because
AFAICT `:declar` implcitly opens a cursor and all of my attempts to
write `@connection.execute("OPEN cur_ex")` threw a syntax error on
`OPEN`. It seems like open isn't supported with the client.

Fixes: #37960
上级 9537dfe1
......@@ -68,7 +68,7 @@ def query(sql, name = nil) #:nodoc:
end
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
:set, :show
:close, :declare, :fetch, :move, :set, :show
) # :nodoc:
private_constant :READ_QUERY
......
......@@ -457,6 +457,19 @@ def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preve
end
end
def test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes
with_example_table do
@connection_handler.while_preventing_writes do
@connection.transaction do
assert_equal [], @connection.execute("DECLARE cur_ex CURSOR FOR SELECT * FROM ex").entries
assert_equal [], @connection.execute("FETCH cur_ex").entries
assert_equal [], @connection.execute("MOVE cur_ex").entries
assert_equal [], @connection.execute("CLOSE cur_ex").entries
end
end
end
end
private
def with_example_table(definition = "id serial primary key, number integer, data character varying(255)", &block)
super(@connection, "ex", definition, &block)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册