How can I get the list of a columns in a table for a SQLite database?

后端 未结 8 1200
梦谈多话
梦谈多话 2020-11-28 23:04

I am looking to retrieve a list of columns in a table. The database is the latest release of SQLite (3.6, I believe). I am looking for code that does this with a SQL query

8条回答
  •  一整个雨季
    2020-11-28 23:43

    I know, it’s been a long time but it’s never too late… I had a similar question with TCL as interpreter and after several search, found nothing good for me. So I propose something based on PRAGMA, knowing that your DB is “main”

    db eval { PRAGMA main.table_info() } TBL { puts $TBL(name) }
    

    And array use to obtain a list

    set col_list {}
    db eval { PRAGMA main.table_info() } TBL { lappend col_list $TBL(name) }
    puts $col_list
    

提交回复
热议问题