Initially I thought that I must to do something like this:
>>>from sqlalchemy import *
>>>db = create_engine('sqlite:///tutorial.db')
>>>metadata = BoundMetaData(db)
>>>print metatada.tables
{}
>>>
but I've received only a empty dict.
What's the right method?
thanks
The metadata only knows about the tables defined in SA. To get all the
tables in the db, do a query like:
select([information_schema.tables.c.table_name,
information_schema.tables.c.table_schema])
Paul
Sorry, but I don't undestand how.
I saw that information_schema is a module inside sqlalchemy/databases/
information_schema.py, but I don't know how call it.
I've tried to do something like this:
>>>from sqlalchemy import *
>>select([information_schema.tables.c.table_name, information_schema.tables.c.table_schema])
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
select([information_schema.tables.c.table_name,information_schema.tables.c.table_schema])
NameError: name 'information_schema' is not defined
What's the right sintax or the part of the documentation I must to
read?
thank you very much
Traceback (most recent call last):
File "autocode.py", line 20, in <module>
tbl = Table(tname, metadata, schema=schema, autoload=True);
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/schema.py", line
143, in __call__
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/engine/base.py",
line 505, in reflecttable
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/databases/
postgres.py", line 385, in reflecttable
KeyError: 'information_schema.cardinal_number'
Somes ideas?
thanks again!
sel="""SELECT table_name FROM all_tables WHERE owner='XXX'""" #
ORACLE
sel="show tables" # MySQL
sel="SELECT name FROM SQLITE_MASTER WHERE type='table'" # SQLite
con=dbengine.connect()
metadata=DynamicMetaData()
tList = con.execute(sel)
tables=[]
for t in tList:
tables.append(Table(t[0], metadata, autoload=True))
that will give you a list of auto-loaded Table objects.
Valentin.