Antonio wrote:
Hi all,

I'm trying to read a pdf file saved in a postgresql table :

pdf_tbl=sqa.Table('pg_largeobject', _mdata,
        sqa.Column('loid', sqa.Integer, primary_key = True),
        sqa.Column('pageno', sqa.Integer),
        sqa.Column('data', sqa.Binary)
)

sqa.mapper(Pdf,pdf_tbl)

sqa.mapper(Pdf,pdf_tbl)

fax_tbl=sqa.Table('faxes', _mdata,
        sqa.Column('id', sqa.Integer, primary_key = True),
        sqa.Column('sender', sqa.TEXT),
        sqa.Column('pages', sqa.SmallInteger),
        sqa.Column('received', sqa.DateTime),
        sqa.Column('filepdf', sqa.Integer,
                sqa.ForeignKey('pg_largeobject.loid'))
)

sqa.mapper(Fax,fax_tbl,properties={ 'pdf': sqa.relation(Pdf) })

sess=sqa.create_session()

qry=sess.query(Fax)
res=qry.get_by(id=1)

print "Content-type:text/pdf\n\n"    # whatever the header is for pdf
for chunk in res.pdf:
   sys.stdout.write(chunk.data)

I would agree that the approach taken by "pg_largeobject" is a useful
approach in that you can read just "chunked" sections.  BLOBs are
supposed to do this for you, but in my experience databases have the
nastiest time trying to produce reasonable APIs that can read the BLOBs
in a streamlike style....since the databases invariably require that
you get a handle on a specific column in a specific row (usually
requiring a one-column selection) and stream from that....doesnt
integrate at all with the usual select/fetch result cycle.

from my own experience with mainly oracle (and ancient years ago
MS-SQL, where I actually wrote C code using DBLIB to do it), JDBC can
barely do it (even though its API supports streaming), DBI can barely
do it, and id bet that DBAPI hardly even makes an attempt.

although im surprised that PG comes with a table called
"pg_largeobject", usually I make my own large object table that
corresponds to the particular objects im storing.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to