aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-28 09:48:16 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-28 09:48:16 -0700
commitfc343d26ffec073c7df64a8a4c2508104f78e9d4 (patch)
tree62424911a0554623b3d5bb5f2b47cb337a99024c /activerecord/lib
parentbf50222b0b5417af554a9a4a8d277f4fccea8f8c (diff)
downloadrails-fc343d26ffec073c7df64a8a4c2508104f78e9d4.tar.gz
rails-fc343d26ffec073c7df64a8a4c2508104f78e9d4.tar.bz2
rails-fc343d26ffec073c7df64a8a4c2508104f78e9d4.zip
clearing statement from cache on exception in order to support older versions of mysql
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 2c05ff21f9..1136dbc45e 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -413,9 +413,19 @@ module ActiveRecord
stmt = cache[:stmt]
end
- stmt.execute(*binds.map { |col, val|
- type_cast(val, col)
- })
+
+ begin
+ stmt.execute(*binds.map { |col, val| type_cast(val, col) })
+ rescue Mysql::Error => e
+ # Older versions of MySQL leave the prepared statement in a bad
+ # place when an error occurs. To support older mysql versions, we
+ # need to close the statement and delete the statement from the
+ # cache.
+ stmt.close
+ @statements.delete sql
+ raise e
+ end
+
if metadata = stmt.result_metadata
cols = cache[:cols] ||= metadata.fetch_fields.map { |field|
field.name