sqlite3 中的列详细信息 [英] column details in sqlite3
本文介绍了sqlite3 中的列详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SQLITE 数据库中,如果我需要表元详细信息,可以运行以下命令
In SQLITE database, if I need table meta details, I can run the following command
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
中做类似的事情.有人能告诉我怎么做吗?
I want to do the similar stuff in sqlalchemy
. Can somebody tell me how to do this ?
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
db_target = create_engine('sqlite:///C:\\Users\\asit\\workspace\\forum1\\src\\sqlite.db')
session = sessionmaker(db_target, autocommit = True)()
rs = session.execute("PRAGMA table_info(forum_forum)")
for row in rs:
print '%s %s %s %s %s' % (row['cid'], row['name'], row['type'], row['notnull'], row['pk'])
输出:-
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
推荐答案
你可以通过以下方式获得很多细节
you can get a lot of details in the following way
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
这篇关于sqlite3 中的列详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文