Getting the type of a column in SQLite

前端 未结 2 571
无人及你
无人及你 2020-12-03 06:14

My mate made the database for my Android app. For example, one of the tables is created like this:

CREATE TABLE table1(
    id_fields_starring INTEGER PRIMAR         


        
2条回答
  •  清歌不尽
    2020-12-03 06:16

    For those of you looking to do this programmatically in Xamarin perhaps (like me) you can execute the PRAGMA query against a SQLiteConnection as follows:

    connection.Query($"PRAGMA table_info({tableName})");
    

    I couldn't find an object defined in the PCL Sqlite package for collecting the result so I created a class to collect the aforementioned components:

    public class SqliteColumninfo
    {
       public string Cid { get; set; }
       public string Name { get; set; }
       public string Type { get; set; }
       public int NotNull { get; set; }
       public int Dflt_Value { get; set; }
       public int PK { get; set; }
    }
    

提交回复
热议问题