binary objects

View: New views
4 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Re: binary objects

by Jacek Kałucki :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Użytkownik John napisał:

> Paul, Larry was able to get Dabo to accept the binary data.  However, we
> followed the idea that each DB adapter had a "fixBinaryData()" method that
> made the correct conversion to allow Dabo to save/update/insert.  Other code
> changes were done too.  But my point is I still think in the end having a
> backend method is going to be a requirment.
>
> For example in the case of Postgres
>
> def fixBinaryData(self, val):
>    return psycopg2.Binary(val)
>    

Hi,

I tried to solve problem my own way.
I tried to encapsulate binary data in dNoEscQuoteStr object, although
noticed two problems:
- first, we need to modify dNoEscQuoteStr class to accept buffer type
object, e.g.:
     def __str__(self):
         if not isinstance(self._value, str):
             ret = array.array("c", self._value).tostring()
         else:
             ret = self._value
         return ret
- second, we need to correct sql expression formatting in
dCursorMixin.__saverow() method
     to avoid UnicodeDecodeError exception.

--
Regards
Jacek Kałucki



_______________________________________________
Post Messages to: Dabo-users@...
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/4AEB1767.1050509@...

Re: binary objects

by John Fabiani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 30 October 2009 09:42:15 am Jacek Kałucki wrote:

> Użytkownik John napisał:
> > Paul, Larry was able to get Dabo to accept the binary data.  However, we
> > followed the idea that each DB adapter had a "fixBinaryData()" method
> > that made the correct conversion to allow Dabo to save/update/insert.
> > Other code changes were done too.  But my point is I still think in the
> > end having a backend method is going to be a requirment.
> >
> > For example in the case of Postgres
> >
> > def fixBinaryData(self, val):
> >    return psycopg2.Binary(val)
>
> Hi,
>
> I tried to solve problem my own way.
> I tried to encapsulate binary data in dNoEscQuoteStr object, although
> noticed two problems:
> - first, we need to modify dNoEscQuoteStr class to accept buffer type
> object, e.g.:
>      def __str__(self):
>          if not isinstance(self._value, str):
>              ret = array.array("c", self._value).tostring()
>          else:
>              ret = self._value
>          return ret
> - second, we need to correct sql expression formatting in
> dCursorMixin.__saverow() method
>      to avoid UnicodeDecodeError exception.

Larry can best respond but I think what you did is similar to his thinking.  
He just hard coded the changes required.  However, even after making his code
changes in the Framework.  It turned out the data was not in the correct
format for DB.  IOW's the backend complained about the data.

That's when I added the method in the db adapter.  It could be my lack
experience with binary data but I could not get
img = buffer(open('whereareyou.jpg').read()) and several other ways
to work.  However, I was able to get it to work using the psycopg2.Binary()
function.  

I think this maybe a problem with other DB's too - else why do they provide
the functions to deal with binary data.

Johnf


_______________________________________________
Post Messages to: Dabo-users@...
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/200910300957.10620.jfabiani@...

Re: binary objects

by Jacek Kałucki :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Użytkownik John napisał:

> Larry can best respond but I think what you did is similar to his thinking.
> He just hard coded the changes required.  However, even after making his code
> changes in the Framework.  It turned out the data was not in the correct
> format for DB.  IOW's the backend complained about the data.
>
> That's when I added the method in the db adapter.  It could be my lack
> experience with binary data but I could not get
> img = buffer(open('whereareyou.jpg').read()) and several other ways
> to work.  However, I was able to get it to work using the psycopg2.Binary()
> function.
>
> I think this maybe a problem with other DB's too - else why do they provide
> the functions to deal with binary data.
>    

Among psycopg2 examples, there is one using both "buffer" and "Binary"
function.
In pure python, both works for me fine.
The reason is, because before string is written into PostgreSQL, it is
parsed (even twice)
by server engine (read pgSQL 8.3 documentation chaper no. 8.4).
They do provide such functions to simplify life :)
But there are solutions that works with all databases universally, like
this:
     INSERT INTO btable (bvalue) values(decode(‘%s’,'base64′));
     SELECT encode(bvalue,’base64′) FROM btable;

--
Regards
Jacek Kałucki



_______________________________________________
Post Messages to: Dabo-users@...
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/4AEB31B0.30401@...

Re: binary objects

by John Fabiani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 30 October 2009 11:34:24 am Jacek Kałucki wrote:

> Użytkownik John napisał:
> > Larry can best respond but I think what you did is similar to his
> > thinking. He just hard coded the changes required.  However, even after
> > making his code changes in the Framework.  It turned out the data was not
> > in the correct format for DB.  IOW's the backend complained about the
> > data.
> >
> > That's when I added the method in the db adapter.  It could be my lack
> > experience with binary data but I could not get
> > img = buffer(open('whereareyou.jpg').read()) and several other ways
> > to work.  However, I was able to get it to work using the
> > psycopg2.Binary() function.
> >
> > I think this maybe a problem with other DB's too - else why do they
> > provide the functions to deal with binary data.
>
> Among psycopg2 examples, there is one using both "buffer" and "Binary"
> function.
> In pure python, both works for me fine.
> The reason is, because before string is written into PostgreSQL, it is
> parsed (even twice)
> by server engine (read pgSQL 8.3 documentation chaper no. 8.4).
> They do provide such functions to simplify life :)
> But there are solutions that works with all databases universally, like
> this:
>      INSERT INTO btable (bvalue) values(decode(‘%s’,'base64′));
>      SELECT encode(bvalue,’base64′) FROM btable;

Yea that's similar to the code I was attempting to get to work.  I'm not the
most talented python coder nor the best SQL coder.  So I could have missed
something.  I'm all in favor of getting a universal way to getting it done.

Johnf


_______________________________________________
Post Messages to: Dabo-users@...
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/200910301203.41726.jfabiani@...
< Prev | 1 - 2 | Next >