Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Eve from Adams' Ribs

Reply
Thread Tools

Eve from Adams' Ribs

 
 
Godwin
Guest
Posts: n/a
 
      08-23-2005
Dear Pythoneer,
I'm thinking of making a class out of an rdbms table name(let's
say oracle).
I can dynamically query the column names and their datatypes from
oracle. So at runtime can i create a class object that creates a class
for example employee with methods that can manipulate that table. For
example :

class Employee(object):

def insert(self,**kwds):
"should insert values into the table based on column and value pairs
supplied"

def update(self,**kwds):
"should update the table"

def delete(self,where):
"should delete a row"

def select(self,*cols,where)
"should retrieve results based on columns and where clause"

But the funny fact is that i want this class to be dynamically
generated at run
time simply from a table name string. "Yes i want to create Eve out of
Adams' rib". I think its possible with python as it is called a dynamic
language. Would u let me on this python secret?

 
Reply With Quote
 
 
 
 
Gregory Bond
Guest
Posts: n/a
 
      08-23-2005
Godwin wrote:

> But the funny fact is that i want this class to be dynamically
> generated at run
> time simply from a table name string.
>


The thing you are looking for is called an "object-relational mapper".

try SQLObject http://sqlobject.org/

This is mainly intended to work the other way (i.e. describe the
structure in Python and create tables from that), but it does support a
"get the structure from a legacy table" mode that may be good enough
(you may be in strife if your existing tables don't meet certain
requirements, like having a unique integer key, or have odd
column-naming schema etc). I don't think it supports Oracle (yet...)
 
Reply With Quote
 
 
 
 
Magnus Lycka
Guest
Posts: n/a
 
      08-23-2005
Godwin wrote:
> I think its possible with python as it is called a dynamic
> language.


Certainly, but what's really the point with these classes?
If they are completely generated from tables, they won't
have different behaviour anyway, just a different chunk
of attributes to fetch, save and update.

It's probably as easy to just have one class, and to have
a dynamic list of attributes and values that you define by
passing in the table name in __init__.
 
Reply With Quote
 
Godwin
Guest
Posts: n/a
 
      08-24-2005
www.devx.com/dbzone/Article/22093

U've made a point and i have seen that approach in the above article.
But i was curious about creating python classes and code on fly. The
only way i could do it was by using exec function. Is there a standard
way of doing it. What are the plus points of such kind of programming?
Is it only done by hackers?

Sorry for asking the wrong question for getting the right answer!

 
Reply With Quote
 
Godwin
Guest
Posts: n/a
 
      08-24-2005
Thanx for the links , i loved the "monty lingua" module
u gave me before.

 
Reply With Quote
 
Godwin
Guest
Posts: n/a
 
      08-24-2005
yes i did hear about sqlobject but as u said it doesn't support oracle
yet. Thanx

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Year's Eve Party in NJ - No Cover Charge Dan Java 0 12-22-2007 05:33 PM
Can you restart a ASP.NET application in the Application_Start eve =?Utf-8?B?bWFzbWl0aA==?= ASP .Net 4 03-21-2007 07:28 PM
NEW Year's Eve and a new IM worm is on the prowl Au79 Computer Support 0 01-01-2006 06:33 AM
Eve Had This Virus?? RahQ5@webtv.net Computer Information 1 04-16-2004 12:10 AM
So what beer are we drinking on this hot summer eve ? slumpy Computer Support 29 08-10-2003 07:12 PM



Advertisments