John wrote:
> On Wednesday 28 October 2009 04:11:14 pm Paul McNett wrote:
>> John wrote:
>>> On Wednesday 28 October 2009 03:20:29 pm Paul McNett wrote:
>>>> John wrote:
>>>>> On Wednesday 28 October 2009 02:59:27 pm Paul McNett wrote:
>>>>>> Just a quick check: is the field defined as a BLOB in your
>>>>>> datastructure? (Type L for bLob).
>>>>> I tried both 'Text' and 'bytea' (large Binary).  No success.
>>>> I'll ask again: what is the contents of biz.DataStructure? Do you see a
>>>> datatype code of "L" for the binary field?
>>>>
>>>> Paul
>>> Sorry about that - I immediately thought about what dbPostgres sets the
>>> columns too.  I missed the point yes it's 'L' for the binary as reported
>>> by bizobj.DataSource.  But we have attempted both 'M' and 'L'.  Larry
>>> tried all day to use binary tools (using 'L' for the column).  I tried
>>> using string tools (using 'M' for the column).   In the end Larry tried
>>> both.
>>>
>>> Maybe we just haven't come up with the right combination.
>> Well, I've racked my brain and I don't think I've ever stored binary stuff
>> in a database, so I can't say for certain that it works.
>>
>> Paul
> 
> I just realized that I have not actually provided the traceback.  As you can 
> see I'm just attempting an save (update).  I'm saving to a Dabo "L" column - 
> and a postgres column type 'bytea' (binary).
> 
> The steps I'm using.
> 
> I have a file that was created using img2py.py.  
> 
> newdata = my_images.jflogosmall.GetData()
> # type(newdata) = str
> pic = dabo.ui.imageFromData(newdata)
> #type(pic) = wx._core.Image
> self.Logo.Picture = pic # this work fine
> self.PrimaryBizobj.setFieldVal('sys_company_logo1', newdata)
> now a simple Form.save()
> 
> If I attempt to save the 'pic' as in
> 
> self.PrimaryBizobj.setFieldVal('sys_company_logo1', pic)
> 
> Then Dabo asks  escQuote() to process the data which of course is wrong.
> 
> I don't know what I'm doing wrong?
> 
> 
> Traceback (most recent call last):
>   File "/home/johnf/dabo/dabo/ui/uiwx/dControlMixin.py", line 27, in _onWxHit
>     self.raiseEvent(dEvents.Hit, evt, *args, **kwargs)
>   File "/home/johnf/dabo/dabo/ui/uiwx/dPemMixin.py", line 952, in raiseEvent
>     super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args, 
> **kwargs)
>   File "/home/johnf/dabo/dabo/lib/eventMixin.py", line 93, in raiseEvent
>     bindingFunction(event)
>   File "/home/johnf/pyProject/court_ordered/SystemClasses.py", line 339, in 
> onSave
>     self.Form.save()
>   File "/home/johnf/dabo/dabo/ui/uiwx/dForm.py", line 383, in save
>     bizobj.saveAll()
>   File "/home/johnf/dabo/dabo/biz/dBizobj.py", line 361, in saveAll
>     startTransaction=False)
>   File "/home/johnf/dabo/dabo/biz/dBizobj.py", line 786, in scanChangedRows
>     func(*args, **kwargs)
>   File "/home/johnf/dabo/dabo/biz/dBizobj.py", line 419, in save
>     cursor.save()
>   File "/home/johnf/dabo/dabo/db/dCursorMixin.py", line 1310, in save
>     saverow(self.RowNumber)
>   File "/home/johnf/dabo/dabo/db/dCursorMixin.py", line 1277, in saverow
>     self.__saverow(row)
>   File "/home/johnf/dabo/dabo/db/dCursorMixin.py", line 1376, in __saverow
>     updClause, pkWhere)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 23: 
> ordinal not in range(128)

Thanks for the traceback. It really helps. Does this patch help 
(untested, and watch for line-wrap):

Index: db/dBackend.py
===================================================================
--- db/dBackend.py      (revision 5507)
+++ db/dBackend.py      (working copy)
@@ -72,7 +72,7 @@
                return cursorClass(self._connection)


-       def formatForQuery(self, val):
+       def formatForQuery(self, val, fieldType=None):
                if isinstance(val, (datetime.date, datetime.datetime)):
                        # Some databases have specific rules for formatting 
date values.
                        return self.formatDateTime(val)
@@ -82,6 +82,8 @@
                        return str(val)
                elif isinstance(val, dNoEscQuoteStr):
                        return val
+               elif fieldType == "L":
+                       return val
                elif val is None:
                        return self.formatNone()
                else:
Index: db/dbSQLite.py
===================================================================
--- db/dbSQLite.py      (revision 5507)
+++ db/dbSQLite.py      (working copy)
@@ -75,7 +75,7 @@
                return self._dictCursorClass
                

-       def formatForQuery(self, val):
+       def formatForQuery(self, val, fieldType=None):
                if isinstance(val, bool):
                        return str(int(val))
                else:
Index: db/dCursorMixin.py
===================================================================
--- db/dCursorMixin.py  (revision 5507)
+++ db/dCursorMixin.py  (working copy)
@@ -1355,7 +1355,8 @@
                                        # Append the field and its value.
                                        flds += ", " + 
self.BackendObject.encloseNames(kk, aq)
                                        # add value to expression
-                                       vals += ", %s" % 
(self.formatForQuery(vv[1]),)
+                                       fieldType = [ds[1] for ds in 
self.DataStructure if ds[0] == kk][0]
+                                       vals += ", %s" % 
(self.formatForQuery(vv[1]), fieldType)

                                # Trim leading comma-space from the strings
                                flds = flds[2:]
@@ -1945,7 +1946,8 @@
                                continue
                        if ret:
                                ret += ", "
-                       ret += tblPrefix + bo.encloseNames(fld, aq) + " = " + 
self.formatForQuery(new_val)
+                       fieldType = [ds[1] for ds in self.DataStructure if 
ds[0] == fld][0]
+                       ret += tblPrefix + bo.encloseNames(fld, aq) + " = " + 
self.formatForQuery(new_val, fieldType)
                return ret

Paul


_______________________________________________
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