method
binary_to_string
v2.1.0 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::PostgreSQLColumn
binary_to_string(value)private
Unescapes bytea output from a database to the binary string it represents.
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 86
def self.binary_to_string(value)
# In each case, check if the value actually is escaped PostgreSQL bytea output
# or an unescaped Active Record attribute that was just written.
if PGconn.respond_to?(:unescape_bytea)
self.class.module_eval do
define_method(:binary_to_string) do |value|
if value =~ /\\\d{3}/
PGconn.unescape_bytea(value)
else
value
end
end
end
else
self.class.module_eval do
define_method(:binary_to_string) do |value|
if value =~ /\\\d{3}/
result = ''
i, max = 0, value.size
while i < max
char = value[i]
if char == ?\\
if value[i+1] == ?\\
char = ?\\
i += 1
else
char = value[i+1..i+3].oct
i += 3
end
end
result << char
i += 1
end
result
else
value
end
end
end
end
self.class.binary_to_string(value)
end Related methods
- Class methods
- new
- Private methods
-
binary_to_string -
extract_value_from_default -
string_to_binary -
extract_precision -
extract_scale -
simplified_type