Storing objects in relational database

2008-05-23 Thread nayden
I started playing with python a few weeks ago after a number of years
of perl programming and I can say that my first impression is,
unsurprisingly, quite positive. ;)
The reason I am writing here is that I can't seem to figure out how to
save/restore python objects into a relational database.  The way I
used to do it in perl was to 'freeze' the object before storing it
into the database and 'thaw' it before restoring it. (For those not
familiar with the perl terminology freeze and thaw are method from
perl's persistence module Storable).  I found that the python's
corresponding module is Pickle but it doesn't seem to work for me.. I
do roughly the following:
class TestA:


def insert():
i = TestA('asdf')
output = cStringIO.StringIO()
cPickle.dump(i, output, 2)
print "output.getvalue(): %s" % output.getvalue()
jd = libpq.PgQuoteBytea(output.getvalue())
print "jd %s" % jd
return dbpool.runOperation("insert into jobs (effective_job_id,
job_description) values (1, " + jd + ")")
--
http://mail.python.org/mailman/listinfo/python-list


Re: Storing objects in relational database

2008-05-23 Thread nayden
and then I try to restore the object with the following code

def success(rv):
print "success"
str =  cStringIO.StringIO(libpq.PgUnQuoteBytea(rv[0][0]))
i = cPickle.load(str)
i.toString()

the execution fails just after the print statement, and I am not quite
sure why is that.

I would love to find out what people are using when they need to do
something similar --
perhaps I am trying to do it the perl way, while there is an elegant
python solution.

thanks
--
http://mail.python.org/mailman/listinfo/python-list