1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

avoiding statement cache if there are no bind values

This commit is contained in:
Aaron Patterson 2010-10-21 11:19:45 -07:00
parent 28a18b5988
commit 1741bbe2d5
2 changed files with 23 additions and 0 deletions

View file

@ -521,6 +521,8 @@ module ActiveRecord
end
def exec(sql, name = 'SQL', binds = [])
return exec_no_cache(sql, name) if binds.empty?
log(sql, name) do
unless @statements.key? sql
nextkey = "a#{@statements.length + 1}"
@ -962,6 +964,15 @@ module ActiveRecord
end
private
def exec_no_cache(sql, name)
log(sql, name) do
result = @connection.async_exec(sql)
ret = ActiveRecord::Result.new(result.fields, result_as_array(result))
result.clear
ret
end
end
# The internal PostgreSQL identifier of the money data type.
MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
# The internal PostgreSQL identifier of the BYTEA data type.

View file

@ -43,6 +43,18 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
end
end
def test_auth_with_bind
assert_nothing_raised do
set_session_auth
USERS.each do |u|
@connection.clear_cache!
set_session_auth u
assert_equal u, @connection.exec("SELECT name FROM #{TABLE_NAME} WHERE id = $1", 'SQL', [[nil, 1]]).first['name']
set_session_auth
end
end
end
def test_schema_uniqueness
assert_nothing_raised do
set_session_auth