From cfc95d89aeffba5a026afcf272bdf3ff231a8983 Mon Sep 17 00:00:00 2001 From: "Juan M. Cuello" Date: Wed, 5 Oct 2011 11:43:03 -0300 Subject: [PATCH] Use the schema_search_path in prepared statements. To allow the use of prepared statements when changing schemas in postgres, the schema search path is added to the sql key. --- .../connection_adapters/postgresql_adapter.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 5402918b1d5bb..d8598432607a6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1035,13 +1035,14 @@ def exec_no_cache(sql, binds) end def exec_cache(sql, binds) - unless @statements.key? sql + sql_key = "#{schema_search_path}-#{sql}" + unless @statements.key? sql_key nextkey = @statements.next_key @connection.prepare nextkey, sql - @statements[sql] = nextkey + @statements[sql_key] = nextkey end - key = @statements[sql] + key = @statements[sql_key] # Clear the queue @connection.get_last_result