column details in sqlite3

后端 未结 2 886
遇见更好的自我
遇见更好的自我 2021-01-23 09:21

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
         


        
相关标签:
2条回答
  • 2021-01-23 10:02

    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 
    
    0 讨论(0)
  • 2021-01-23 10:06

    You can run arbitrary SQL statements with session.execute(), including that pragma statement.

    The PRAGMA table_info(forum_forum) statement returns a sequence of rows:

    >>> 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)
    
    0 讨论(0)
提交回复
热议问题