Files

Postgres::Conversion

Public Instance Methods

decode_array(str, delim=',', &conv_proc) click to toggle source
# File lib/postgres-pr/typeconv/array.rb, line 5
def decode_array(str, delim=',', &conv_proc)
  delim = Regexp.escape(delim)
  buf = StringScanner.new(str)
  return parse_arr(buf, delim, &conv_proc)
ensure
  raise ConversionError, "end of string expected (#{buf.rest})" unless buf.empty?
end
decode_bytea(str) click to toggle source

Decodes a bytea encoded string.

for decoding rules see:

http://www.postgresql.org/docs/7.4/static/datatype-binary.html
# File lib/postgres-pr/typeconv/bytea.rb, line 20
def decode_bytea(str)
  str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s|
    if s.size == 2 then s[1,1] else s[1,3].oct.chr end
  }
end
encode_bytea(str) click to toggle source

Encodes a string as bytea value.

for encoding rules see:

http://www.postgresql.org/docs/7.4/static/datatype-binary.html
# File lib/postgres-pr/typeconv/bytea.rb, line 10
def encode_bytea(str)
  str.gsub(/[\0000-\0037\0047\1134\1177-\3377]/) {|b| "\\#{ b[0].to_s(8).rjust(3, '0') }" }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.