On Thursday 29 October 2009 09:00:04 am Paul McNett wrote:
> [email protected] wrote:
> > Paul,
> >
> > In line 1377 of dCursorMixin where we are building the sql update
> > statement there is a problem handling binary data.  Converting string
> > data to unicode won't work for string data for byte values > 128.
> >
> > For example, u'\x55' is OK but u'\xFF' is not allowed.
> >
> > When we do the string substitution, if any string is unicode, then the
> > entire string is implicitly converted to unicode.  In our case it's
> > something like ...sql="set %s = %s"%(u'fieldname','\xFF') so it barfs.
> >
> > I think if we wrap the first parameter with a str() command that it may
> > work assuming that the field name should never need to be in unicode.
>
> I agree that we don't want to try to convert binary data to unicode,
> especially not using the ascii codec.
>
> > What cha think?
>
> Did you try my patch?
>
> Paul

first in dCursorMixin.py  formatForQuery() needs fieldType.

def formatForQuery(self, val, fieldType=None):

We have been trying your patch all morning.  We sort of got it pass the sql 
update statement by forcing it to str (not in your patch).  But now have 
trouble with the database seeing it as a string and not binary info.  

I coming to the conclusion that we need a special method to handle binary data 
in the DB adapter.  In the O'Reilly python cookbook it is suggested that 
MySQL and Postgres require special functions to insert binary data (other 
DB's may need special functions too).  I have confirmed the functions for 
Postgres.  MySQL has a function "escape_string" that will accept a pickle to 
allow inserts of binary data.

Now that I said the above I have to note that the book is old.  I did also 
discover that the following will create the binary data
 picdata = buffer(open('whereareyou.jpg').read()) 

and a simple statement  

cursor.execute("INSERT INTO test_binary   VALUES ( %(img)s)", picdata)

works outside of Dabo.  I don't need any special functions for Postgres.

I just can't get it to work with Dabo.  

Johnf






_______________________________________________
Post Messages to: [email protected]
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/[email protected]

Reply via email to