aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-07-06 14:53:43 -0600
committerSean Griffin <sean@thoughtbot.com>2014-07-06 14:53:43 -0600
commitf6968bd601e38fb5060c7bc577331f97ed5e232c (patch)
treedbc7818b5b6fed9c88f9391a18948b84d5995103 /activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb
parent2f716694f20cd19464029513fb59440fd9000840 (diff)
downloadrails-f6968bd601e38fb5060c7bc577331f97ed5e232c.tar.gz
rails-f6968bd601e38fb5060c7bc577331f97ed5e232c.tar.bz2
rails-f6968bd601e38fb5060c7bc577331f97ed5e232c.zip
Don't rely on the sql type to quote XML columns in PG
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb
new file mode 100644
index 0000000000..7323f12763
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/xml.rb
@@ -0,0 +1,32 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module PostgreSQL
+ module OID # :nodoc:
+ class Xml < Type::String # :nodoc:
+ def type
+ :xml
+ end
+
+ def text?
+ false
+ end
+
+ def type_cast_for_database(value)
+ return unless value
+ Data.new(super)
+ end
+
+ class Data # :nodoc:
+ def initialize(value)
+ @value = value
+ end
+
+ def to_s
+ @value
+ end
+ end
+ end
+ end
+ end
+ end
+end