mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Pass binds through on PostgreSQL exec_query even when prepared statements are off globally
This commit is contained in:
parent
fc96b3bf3e
commit
724b733c45
2 changed files with 20 additions and 24 deletions
|
@ -653,9 +653,7 @@ module ActiveRecord
|
|||
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)
|
||||
|
|
|
@ -254,35 +254,33 @@ module ActiveRecord
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue