提交 3088d236 编写于 作者: A Aaron Patterson

Merge pull request #3232 from Juanmcuello/pg_prepared_statements

Use the schema_search_path in prepared statements.
...@@ -1035,13 +1035,14 @@ def exec_no_cache(sql, binds) ...@@ -1035,13 +1035,14 @@ def exec_no_cache(sql, binds)
end end
def exec_cache(sql, binds) def exec_cache(sql, binds)
unless @statements.key? sql sql_key = "#{schema_search_path}-#{sql}"
unless @statements.key? sql_key
nextkey = @statements.next_key nextkey = @statements.next_key
@connection.prepare nextkey, sql @connection.prepare nextkey, sql
@statements[sql] = nextkey @statements[sql_key] = nextkey
end end
key = @statements[sql] key = @statements[sql_key]
# Clear the queue # Clear the queue
@connection.get_last_result @connection.get_last_result
......
...@@ -38,6 +38,10 @@ class Thing4 < ActiveRecord::Base ...@@ -38,6 +38,10 @@ class Thing4 < ActiveRecord::Base
set_table_name 'test_schema."Things"' set_table_name 'test_schema."Things"'
end end
class Thing5 < ActiveRecord::Base
set_table_name 'things'
end
def setup def setup
@connection = ActiveRecord::Base.connection @connection = ActiveRecord::Base.connection
@connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})" @connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
...@@ -236,6 +240,21 @@ def test_current_schema ...@@ -236,6 +240,21 @@ def test_current_schema
end end
end end
def test_prepared_statements_with_multiple_schemas
@connection.schema_search_path = SCHEMA_NAME
Thing5.create(:id => 1, :name => "thing inside #{SCHEMA_NAME}", :email => "thing1@localhost", :moment => Time.now)
@connection.schema_search_path = SCHEMA2_NAME
Thing5.create(:id => 1, :name => "thing inside #{SCHEMA2_NAME}", :email => "thing1@localhost", :moment => Time.now)
@connection.schema_search_path = SCHEMA_NAME
assert_equal 1, Thing5.count
@connection.schema_search_path = SCHEMA2_NAME
assert_equal 1, Thing5.count
end
def test_schema_exists? def test_schema_exists?
{ {
'public' => true, 'public' => true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册