Miguel Lopes wrote:
> On Fri, Nov 13, 2009 at 4:18 AM, Ed Leafe <[email protected]> wrote:
>> On Nov 12, 2009, at 6:20 PM, Miguel Lopes wrote:
>>
>>> Any clues on how I can save a pdf to a blob and then have a remote
>>> Dabo desktop application open it?
>>>
>>> I'm not sure this is really a Dabo question, but I figure it must be
>>> relatively common.
>>> In my case the user could save something to a remote database and then
>>> retrive it back at some later date.
>>> Are there any facilities in Dabo related to this functionality?
>>
>> Not explicitly, no. And I know that recently there has been some
>> discussion on the dev list about some issues with saving binaries with
>> some database backends.
>
> Is perhaps any of these backends SQLite?
Yes, and I think the problem would affect all backends. Here's the
traceback I receive when running a program that creates a new record in
a bizobj, puts some binary image data into a blob field, and then calls
biz.save():
Traceback (most recent call last):
File "binary.py", line 18, in <module>
biz.save()
File "/home/pmcnett/dabo-full/trunk/dabo/biz/dBizobj.py", line 419,
in save
cursor.save()
File "/home/pmcnett/dabo-full/trunk/dabo/db/dCursorMixin.py", line
1310, in save
saverow(self.RowNumber)
File "/home/pmcnett/dabo-full/trunk/dabo/db/dCursorMixin.py", line
1277, in saverow
self.__saverow(row)
File "/home/pmcnett/dabo-full/trunk/dabo/db/dCursorMixin.py", line
1371, in __saverow
self.BackendObject.encloseNames(self.Table, aq), flds, vals)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 0:
ordinal not in range(128)
>> In general, though, I would imagine that you would read in the pdf
>> using regular Python code, and then save it to a BLOB column:
>> pdfbin = file("document.pdf", "rb").read()
>> biz.setFieldVal("some_blob_column", pdfbin)
>> biz.save()
As soon as we get this bug resolved, I agree that's what you would do.
> With SQLite the following code is failing:
>
> def newDoc(self, evt):
> pdffile = dabo.ui.getFile()
> pdfbin = file(pdffile, "rb").read()
> pdfname = pdffile[pdffile.rindex('/')+1:]
> self.new()
> biz = self.PrimaryBizobj
> biz.setFieldVal("attachment", pdfbin)
> biz.setFieldVal("document", pdfname)
> self.save()
>
> After this code runs the current Record is holding the data, but the
> save failed silently!
> I've only tested this on SQLite.
I don't know why it failed silently. Here's the test code I used (save
it as a program and run it).
{{{
import dabo
from dabo.lib import getRandomUUID
picdata = buffer(open("ss/resources/icon_green_16px.png").read())
con = dabo.db.connect(":memory:")
cur = con.cursor()
cur.execute("create table test (id PRIMARY KEY, img BLOB)")
biz = dabo.biz.dBizobj(con, DataSource="test", KeyField="id")
biz.DefaultValues["id"] = getRandomUUID
biz.new()
biz.Record.img = picdata
print len(biz.Record.img)
biz.save()
biz.requery()
print len(biz.Record.img)
}}}
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]