简体   繁体   中英

How do I programmatically list all the data types in a SQLite database?

Using C# with non-SQLite databases (such as SQL Server, Oracle, etc), you can loop through the DataTable returned from DbConnection.GetSchema("DataTypes") to look at all the supported data types of that database.

Unfortunately, Microsoft.Data.Sqlite.SqliteConnection does not support the GetSchema() method. So, how can I programmatically list all the supported data types in a SQLite database?

In order to programatically determine all data types used in a particular SQLite database schema, you can leverage the sqlite_master table in conjunction with a pragma statement for each table.

In two steps:

  1. Execute the query:
 select tbl_name from sqlite_master where type = 'table';
  1. Iterate over each table name (tbl_name) returned from the query and run the query:

pragma table_info(tbl_name);

Use the returned type column to build your unique list of date types used across the entire database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM