aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-13 11:18:11 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:09 -0700
commit050d7d3e4979c88e8df46b69e6953599c09f6c18 (patch)
treeedb380d975b84b7a0fbe61c006dd9f2ce16a2405 /activerecord
parentd4b0bcb88e058a642b193b9e008b43a32fd64d64 (diff)
downloadrails-050d7d3e4979c88e8df46b69e6953599c09f6c18.tar.gz
rails-050d7d3e4979c88e8df46b69e6953599c09f6c18.tar.bz2
rails-050d7d3e4979c88e8df46b69e6953599c09f6c18.zip
statements are cached, cache is cleared on reconnect
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index a4cd2cd964..1c32f64d92 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -194,6 +194,7 @@ module ActiveRecord
super(connection, logger)
@connection_options, @config = connection_options, config
@quoted_column_names, @quoted_table_names = {}, {}
+ @statements = {}
connect
end
@@ -285,6 +286,7 @@ module ActiveRecord
def reconnect!
disconnect!
+ clear_cache!
connect
end
@@ -313,10 +315,23 @@ module ActiveRecord
rows
end
+ def clear_cache!
+ @statements.values.each do |stmt|
+ stmt.close
+ end
+ @statements.clear
+ end
+
def exec(sql, name = 'SQL', bind_values = [])
log(sql, name) do
result = nil
- stmt = @connection.prepare(sql)
+
+ if bind_values.empty?
+ stmt = @connection.prepare(sql)
+ else
+ stmt = @statements[sql] ||= @connection.prepare(sql)
+ end
+
stmt.execute(*bind_values.map { |col, val|
col ? col.type_cast(val) : val
})
@@ -326,7 +341,9 @@ module ActiveRecord
stmt.each { |thing| values << thing }
result = ActiveRecord::Result.new(cols, values)
end
- stmt.close
+
+ stmt.close if bind_values.empty?
+
result
end
end