Eve from Adams' Ribs

Discussion in 'Python' started by Godwin, Aug 23, 2005.

  1. Godwin

    Godwin Guest

    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?
     
    Godwin, Aug 23, 2005
    #1
    1. Advertising

  2. Godwin

    Gregory Bond Guest

    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...)
     
    Gregory Bond, Aug 23, 2005
    #2
    1. Advertising

  3. Godwin

    gene tani Guest

  4. Godwin

    Magnus Lycka Guest

    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__.
     
    Magnus Lycka, Aug 23, 2005
    #4
  5. Godwin

    Godwin Guest

    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!
     
    Godwin, Aug 24, 2005
    #5
  6. Godwin

    Godwin Guest

    Thanx for the links , i loved the "monty lingua" module
    u gave me before.
     
    Godwin, Aug 24, 2005
    #6
  7. Godwin

    Godwin Guest

    yes i did hear about sqlobject but as u said it doesn't support oracle
    yet. Thanx
     
    Godwin, Aug 24, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    310
  2. =?Utf-8?B?bWFzbWl0aA==?=
    Replies:
    4
    Views:
    455
    Cowboy \(Gregory A. Beamer\)
    Mar 21, 2007
  3. Dan
    Replies:
    0
    Views:
    365
Loading...

Share This Page