aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-13 15:35:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-14 13:37:39 -0700
commita0d4c8d1bf2198608e2e319ff833560f88d20855 (patch)
tree89c102800b139109bd3385ed0fed2d2d84e00c82 /activerecord/lib
parent27f8c57f5f88304212a00cb8e32f8227755a7265 (diff)
downloadrails-a0d4c8d1bf2198608e2e319ff833560f88d20855.tar.gz
rails-a0d4c8d1bf2198608e2e319ff833560f88d20855.tar.bz2
rails-a0d4c8d1bf2198608e2e319ff833560f88d20855.zip
using the database adapter to typecast before executing prepared statement
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb14
2 files changed, 14 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 f461162dde..085357678c 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -403,7 +403,7 @@ module ActiveRecord
end
stmt.execute(*binds.map { |col, val|
- col ? col.type_cast(val) : val
+ type_cast(val, col)
})
if metadata = stmt.result_metadata
cols = cache[:cols] ||= metadata.fetch_fields.map { |field|
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 0884968363..e74ec84e81 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -360,6 +360,18 @@ module ActiveRecord
end
end
+ def type_cast(value, column)
+ return super unless column
+
+ case value
+ when String
+ return super unless 'bytea' == column.sql_type
+ escape_bytea(value)
+ else
+ super
+ end
+ end
+
# Quotes strings for use in SQL input.
def quote_string(s) #:nodoc:
@connection.escape(s)
@@ -530,7 +542,7 @@ module ActiveRecord
# Clear the queue
@connection.get_last_result
@connection.send_query_prepared(key, binds.map { |col, val|
- col ? col.type_cast(val) : val
+ type_cast(val, col)
})
@connection.block
result = @connection.get_last_result