In July 06, Oleg suggested the following code:
(see
http://pythonpaste.org/archives/message/
20060601.075828.a082c271.en.html)
tables = {}
for table_name in my_list_of_tables:
class Table(SQLObject):
class sqlmeta:
table=table_name
fromDatabase=True
tables[table_name] = Table
This is exactly what I'd like to do. However, when I run something
very similar:
from sqlobject import *
sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
class Person1(SQLObject):
lname = StringCol()
Person1.createTable()
class Person2(SQLObject):
lname = StringCol()
Person2.createTable()
tables = {}
for table_name in ['person1', 'person2']:
class Table(SQLObject):
class sqlmeta:
table=table_name
fromDatabase=True
tables[table_name] = Table
print 'created %s' % table_name
I get an error on attempting to reconnect with the second table:
...
created person1
Traceback (most recent call last):
File "dyn1.py", line 12, in ?
class Table(SQLObject):
File "/Library/Python/2.3/site-packages/SQLObject-0.9dev_r2175-
py2.3.egg/sqlobject/declarative.py", line 117, in __new__
cls.__classinit__(cls, new_attrs)
File "/Library/Python/2.3/site-packages/SQLObject-0.9dev_r2175-
py2.3.egg/sqlobject/main.py", line 829, in __classinit__
classregistry.registry(cls.sqlmeta.registry).addClass(cls)
File "/Library/Python/2.3/site-packages/SQLObject-0.9dev_r2175-
py2.3.egg/sqlobject/classregistry.py", line 91, in addClass
'__file__', '(unknown)')))
ValueError: class Table is already in the registry (other class is
<class '__main__.Table'>, from the module __main__ in dyn1.py;
attempted new class is <class '__main__.Table'>, from the module
__main__ in dyn1.py)
Is there a way to do this?
(What I'd really like to do is create a Class that optionally takes a
unique_id argument and when unique_id is set, uses that to set the
'table' attribute for sqlmeta and sets fromDatabase True.)
Thanks.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss