Permalink
Browse files

Add OID::Bit for supporting bit string.

  • Loading branch information...
1 parent 0141dd3 commit 9339005bb5504839e2a868f9510f0610da657400 @kennyj kennyj committed Apr 15, 2013
@@ -26,6 +26,13 @@ def string_to_time(string)
end
end
+ def string_to_bit(value)
+ case value
+ when /^[01]*$/ then value # Bit-string notation
+ when /^[0-9A-F]*$/i then value.hex.to_s(2) # Hexadecimal notation
+ end
+ end
+
def hstore_to_string(object)
if Hash === object
object.map { |k,v|
@@ -18,6 +18,16 @@ def type_cast(value)
end
end
+ class Bit < Type
+ def type_cast(value)
+ if String === value
+ ConnectionAdapters::PostgreSQLColumn.string_to_bit value
+ else
+ value
+ end
+ end
+ end
+
class Bytea < Type
def type_cast(value)
return if value.nil?
@@ -323,14 +333,14 @@ def self.registered_type?(name)
# FIXME: why are we keeping these types as strings?
alias_type 'tsvector', 'text'
alias_type 'interval', 'text'
- alias_type 'bit', 'text'
- alias_type 'varbit', 'text'
alias_type 'macaddr', 'text'
alias_type 'uuid', 'text'
register_type 'money', OID::Money.new
register_type 'bytea', OID::Bytea.new
register_type 'bool', OID::Boolean.new
+ register_type 'bit', OID::Bit.new
+ register_type 'varbit', OID::Bit.new
register_type 'float4', OID::Float.new
alias_type 'float8', 'float4'

0 comments on commit 9339005

Please sign in to comment.