How to get a list of column names on Sqlite3 database?

后端 未结 18 1382
半阙折子戏
半阙折子戏 2020-11-27 08:48

I want to migrate my iPhone app to a new database version. Since I don\'t have some version saved, I need to check if certain column names exist.

This Stackoverflow

18条回答
  •  长情又很酷
    2020-11-27 09:23

    An alternative way to get a list of column names not mentioned here is to select from a pragma function:

    SELECT name FROM PRAGMA_TABLE_INFO('your_table');
    name      
    tbl_name  
    rootpage  
    sql
    

    You can check if a certain column exists by running:

    SELECT 1 FROM PRAGMA_TABLE_INFO('your_table') WHERE name='sql';
    1
    

    This is what you use if you don't want to parse the result of select sql from sqlite_master or pragma table_info.

    Reference:

    https://www.sqlite.org/pragma.html#pragfunc

提交回复
热议问题