aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-11 14:12:31 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-11 14:12:31 -0700
commit75dc9fbac76a2da78b8d21e1ede16fea38d16564 (patch)
tree9c297bb869e37c8b991091ced632988e5b39e8cb /activerecord/lib
parentf6c0c8ff6101fed24dd176fb0cce0383807c502d (diff)
downloadrails-75dc9fbac76a2da78b8d21e1ede16fea38d16564.tar.gz
rails-75dc9fbac76a2da78b8d21e1ede16fea38d16564.tar.bz2
rails-75dc9fbac76a2da78b8d21e1ede16fea38d16564.zip
cache table exists queries in prepared statement cache
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb9
1 files changed, 6 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 d76b03e80a..015d5eb646 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -637,11 +637,14 @@ module ActiveRecord
def table_exists?(name)
schema, table = extract_schema_and_table(name.to_s)
- query(<<-SQL, 'SCHEMA').first[0].to_i > 0
+ binds = [[nil, table.gsub(/(^"|"$)/,'')]]
+ binds << [nil, schema] if schema
+
+ exec_query(<<-SQL, 'SCHEMA', binds).rows.first[0].to_i > 0
SELECT COUNT(*)
FROM pg_tables
- WHERE tablename = '#{table.gsub(/(^"|"$)/,'')}'
- #{schema ? "AND schemaname = '#{schema}'" : ''}
+ WHERE tablename = $1
+ #{schema ? "AND schemaname = $2" : ''}
SQL
end