Python sqlite3中的列详细信息

Python sqlite3中的列详细信息,python,sqlite,sqlalchemy,Python,Sqlite,Sqlalchemy,在SQLITE数据库中,如果需要表元详细信息,可以运行以下命令 C:\sqlite>sqlite3.exe sqlite2.db SQLite version 3.7.15 2012-12-12 13:36:53 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> PRAGMA table_info(forum_forum); 0|id|integer|1||1 1|cat

在SQLITE数据库中,如果需要表元详细信息,可以运行以下命令

C:\sqlite>sqlite3.exe sqlite2.db
SQLite version 3.7.15 2012-12-12 13:36:53
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA table_info(forum_forum);
0|id|integer|1||1
1|category_id|integer|0||0
2|name|varchar(100)|1||0
3|description|varchar(200)|1||0
4|locked|bool|1||0
我想在sqlalchemy中做类似的事情。谁能告诉我怎么做

解决方案 输出:-

0 id integer 1 1
1 category_id integer 0 0
2 name varchar(100) 1 0
3 description varchar(200) 1 0
4 locked bool 1 0

可以使用运行任意SQL语句,包括该pragma语句

PRAGMA table_infoforum_forum语句返回一系列行:

>>> res = session.execute("PRAGMA table_info(forum_forum)")
>>> res.keys()
[u'cid', u'name', u'type', u'notnull', u'dflt_value', u'pk']
>>> for row in res:
...     print row
... 
(0, u'id', u'integer', 0, None, 1)
(1, u'category_id', u'integer', 0, None, 0)
(2, u'name', u'varchar(100)', 1, None, 0)
(3, u'description', u'varchar(200)', 1, None, 0)
(4, u'locked', u'bool', 1, None, 0)

您可以通过以下方式获得许多详细信息

from sqlalchemy import *

db_target = create_engine('sqlite:///C:\\Users\\asit\\workspace\\forum1\\src\\sqlite.db')
target_metadata = MetaData(db_target)
src_master_table = Table('forum_forum', src_metadata, autoload=True )
print src_master_table.columns._data 

不要在你的问题中张贴你的解决方案。把它作为答案贴出来,我的答案对你有帮助吗?谢谢martijn。你的回答帮助了我。在这方面,我是根据你的回答来解决的。
from sqlalchemy import *

db_target = create_engine('sqlite:///C:\\Users\\asit\\workspace\\forum1\\src\\sqlite.db')
target_metadata = MetaData(db_target)
src_master_table = Table('forum_forum', src_metadata, autoload=True )
print src_master_table.columns._data