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

Pass binds on PostgreSQL exec_query even when prepared statements off globally #41300

Merged
merged 1 commit into from Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -653,9 +653,7 @@ def execute_and_clear(sql, name, binds, prepare: false)
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
end

if without_prepared_statement?(binds)
result = exec_no_cache(sql, name, [])
elsif !prepare
if !prepare || without_prepared_statement?(binds)
result = exec_no_cache(sql, name, binds)
else
result = exec_cache(sql, name, binds)
Expand Down
Expand Up @@ -254,35 +254,33 @@ def test_exec_no_binds
end
end

if ActiveRecord::Base.connection.prepared_statements
def test_exec_with_binds
with_example_table do
string = @connection.quote("foo")
@connection.exec_query("INSERT INTO ex (id, data) VALUES (1, #{string})")
def test_exec_with_binds
with_example_table do
string = @connection.quote("foo")
@connection.exec_query("INSERT INTO ex (id, data) VALUES (1, #{string})")

bind = Relation::QueryAttribute.new("id", 1, Type::Value.new)
result = @connection.exec_query("SELECT id, data FROM ex WHERE id = $1", nil, [bind])
bind = Relation::QueryAttribute.new("id", 1, Type::Value.new)
result = @connection.exec_query("SELECT id, data FROM ex WHERE id = $1", nil, [bind])

assert_equal 1, result.rows.length
assert_equal 2, result.columns.length
assert_equal 1, result.rows.length
assert_equal 2, result.columns.length

assert_equal [[1, "foo"]], result.rows
end
assert_equal [[1, "foo"]], result.rows
end
end

def test_exec_typecasts_bind_vals
with_example_table do
string = @connection.quote("foo")
@connection.exec_query("INSERT INTO ex (id, data) VALUES (1, #{string})")
def test_exec_typecasts_bind_vals
with_example_table do
string = @connection.quote("foo")
@connection.exec_query("INSERT INTO ex (id, data) VALUES (1, #{string})")

bind = Relation::QueryAttribute.new("id", "1-fuu", Type::Integer.new)
result = @connection.exec_query("SELECT id, data FROM ex WHERE id = $1", nil, [bind])
bind = Relation::QueryAttribute.new("id", "1-fuu", Type::Integer.new)
result = @connection.exec_query("SELECT id, data FROM ex WHERE id = $1", nil, [bind])

assert_equal 1, result.rows.length
assert_equal 2, result.columns.length
assert_equal 1, result.rows.length
assert_equal 2, result.columns.length

assert_equal [[1, "foo"]], result.rows
end
assert_equal [[1, "foo"]], result.rows
end
end

Expand Down