[DB-SIG] Oracle tables encapsulation

Jim Fulton jim@digicool.com
Thu, 02 Dec 1999 14:58:40 +0000

Olivier BERGER wrote:
> Hi python fans.
> I've searched a bit the archives or general Python DB documentation, but
> couldn't find any clue on this, so I'm asking you, and pardon me if this is
> a really trivial question about Python DB usage...
> I'd like to have a Python framework with classes encapsulating the physical
> tables and columns of my Oracle database.
> For instance, I would have a class called OracleRow which would allow me to
> map automatically the results of DCOracle fetch results to an instance of a
> subclass of OracleRow.
> This would, for instance, give the following :
> class MyTable(OracleTable) :
>     def __init__(self) :
>         OracleTable("mytable")
> ...
> ... so that I get a MyTableRow class corresponding to rows in the MYTABLE
> oracle table, and then I would be able to do something like
> cursor.execute("select * from mytable")
> for r in cursor.fetchall :
>     instance = MyTableRow(r)
>     do_something(instance)
> and if MYTABLE contained the ID, NAME, ADDRESS columns, then I would be able
> to do a :
> def do_something(mytablerow) :
>     print mytablerow.id, mytablerow.name, mytablerow.address
> As you see this kind of framework would allow me to use the MyTableRow
> containing attributes allready mapped to the corresponding columns of the
> Oracle table. This would have been made by analysing the oracle meta-model
> internal tables in order to know the proper mapping.
> Such a framework allows automatical encapsulation of low-level tables into
> obect instances, thus facilitating the algorithms writing.
> Have you experienced this kind of framework, and can you direct me to the
> corresponding source code (if available) so that I won't code it myself
> (with all the resulting errors... ;)

You should look at the SQL Methods facility in Zope (www.zope.org). 
It does exactly this. I suggest that you download Zope and take 
a look at the file lib/python/Shared/DC/ZRDB/Results.py.


Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for