473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Eve from Adams' Ribs

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?

Aug 23 '05 #1
6 1093
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...)
Aug 23 '05 #2
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__.
Aug 23 '05 #4
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!

Aug 24 '05 #5
Thanx for the links , i loved the "monty lingua" module
u gave me before.

Aug 24 '05 #6
yes i did hear about sqlobject but as u said it doesn't support oracle
yet. Thanx

Aug 24 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: The Bicycling Guitarist | last post by:
The nav bars of my web site break at least three different ways depending on which browser is used, and they're all ugly. I've tried adding white-space: nowrap; to the li. It breaks better in MSIE...
6
by: Bob | last post by:
It's been quite a while since I've built an Access database, but I suppose it's like riding a bicycle and it will all come back to me. But I'm not sure Access is the proper tool for what I want to...
4
by: Takeadoe | last post by:
Dear NGs, I recently downloaded and read a bunch of material on normalizing your data and db design. Things aren't crystal clear yet! Part of the problem is that nearly every thing I read...
0
by: boris.smirnov | last post by:
Hello all, i need to call python from msc.adams. the syntax is "mdi -c python exit" I have created a linux script called "run_python" with this content: mdi -c python $* exit then a call...
0
by: canna37267 | last post by:
patch adams movie http://cracks.00bp.com F R E E
0
by: savare.grove | last post by:
patch adams hospital http://cracks.12w.net F R E E
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.