[Nitro] Storing binary data

George Moschovitis george.moschovitis at gmail.com
Tue Jun 14 07:58:36 EDT 2005


Hello Michael,

thanks a lot for the patch, I 'll integrate this. I 'll try to add
support for blobs in 0.20.0,
I 'll have a look at DBI first.

At the moment I want to implement, a really really cool feature in Og,
stay tuned :)

-g.

On 6/14/05, Michael Neumann <mneumann at ntecs.de> wrote:
> Am Tuesday 14 June 2005 13:29 schrieb George Moschovitis:
> > Hello Michael
> >
> > when recoding the psql driver I forgot to overide the default mapping to a
> > blob column that was included in earlier versions of the Og-Psql adapter.
> > The prefered way is BYTEA, and this will be fixed in the imminent 0.19.0
> > release of Og.
> 
> Here's my patch/override to enable BYTEA's:
> 
> class Og::Binary; end # tag for binary properties
> 
> require 'og/adapters/psql'
> class Og::PsqlAdapter
> 
>   class << self
>     #
>     # Encodes a string as bytea value.
>     #
>     # for encoding rules see:
>     #   http://www.postgresql.org/docs/7.4/static/datatype-binary.html
>     #
> 
>     def encode_bytea(str)
>       str.gsub(/[\000-\037\047\134\177-\377]/) {|b|
> "\\#{ b[0].to_s(8).rjust(3, '0') }" }
>     end
> 
>     #
>     # Decodes a bytea encoded string.
>     #
>     # for decoding rules see:
>     #   http://www.postgresql.org/docs/7.4/static/datatype-binary.html
>     #
>     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
>   end
> 
>   alias __old_read_prop read_prop
>   alias __old_write_prop write_prop
> 
>   def read_prop(p, idx)
>     if p.klass.ancestors.include?(Og::Binary)
>       return "#{ self.class }.decode_bytea(res.getvalue(tuple, #{idx}))"
>     else
>       __old_read_prop(p, idx)
>     end
>   end
> 
>   def write_prop(p)
>     if p.klass.ancestors.include?(Og::Binary)
>       return %|#\{@#{p.symbol} ?
> "'#\{#{self.class}.escape(#{self.class}.encode_bytea(@#{p.symbol}))\}'" :
> 'NULL'\}|
>     else
>       __old_write_prop(p)
>     end
>   end
> end
> 
> 
> > Do you think than BLOB is better than BYTEA?
> 
> Blobs are actually a lot faster (and uses up less storage) for large data I
> think, as they need not to be encoded and decoded. I'd like to have both ;-)
> BYTEA is easier to handle than BLOBs, but if you implement BLOBs in a way
> that they are transparent to the user (as I did in Ruby/DBI), I'd prefer that
> way.
> 
> Regards,
> 
>   Michael
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
> 


-- 
http://nitro.rubyforge.org
http://www.joy.gr




More information about the Nitro-general mailing list