aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2014-06-04 02:54:40 +0930
committerMatthew Draper <matthew@trebex.net>2014-06-04 02:54:40 +0930
commit7a25444f182f76696ab1f0824464025a9e121f8e (patch)
treeb3dedecdebc71d108a34fcf3e06eda8a07503084 /activerecord/lib/active_record/connection_adapters/postgresql
parent4bcf9029452e0c760af04faab6b549710401e8cf (diff)
parent74a756a8b43e2eb5e743d32fa4f6089be2246a58 (diff)
downloadrails-7a25444f182f76696ab1f0824464025a9e121f8e.tar.gz
rails-7a25444f182f76696ab1f0824464025a9e121f8e.tar.bz2
rails-7a25444f182f76696ab1f0824464025a9e121f8e.zip
Merge pull request #15486 from sgrif/sg-binary-quoting
Refactor quoting of binary data to not be based on the column type
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb31
1 files changed, 21 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
index c875bc5162..4c719b834f 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -61,7 +61,6 @@ module ActiveRecord
end
when String
case sql_type
- when 'bytea' then "'#{escape_bytea(value)}'"
when 'xml' then "xml '#{quote_string(value)}'"
when /^bit/
case value
@@ -105,15 +104,6 @@ module ActiveRecord
super(value, column)
end
end
- when String
- if 'bytea' == column.sql_type
- # Return a bind param hash with format as binary.
- # See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
- # for more information
- { value: value, format: 1 }
- else
- super(value, column)
- end
when Hash
case column.sql_type
when 'hstore' then PostgreSQLColumn.hstore_to_string(value, array_member)
@@ -173,6 +163,27 @@ module ActiveRecord
quote(value, column)
end
end
+
+ private
+
+ def _quote(value)
+ if value.is_a?(Type::Binary::Data)
+ "'#{escape_bytea(value.to_s)}'"
+ else
+ super
+ end
+ end
+
+ def _type_cast(value)
+ if value.is_a?(Type::Binary::Data)
+ # Return a bind param hash with format as binary.
+ # See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
+ # for more information
+ { value: value.to_s, format: 1 }
+ else
+ super
+ end
+ end
end
end
end