获取表架构似乎不适用于 System.Data.SQLite
我使用 SQLite.NET 访问数据库,在一种特殊情况下,我需要获取表架构,因为它是特定于应用程序的。
我一直在浏览 SQLite.NET 论坛和谷歌,它看起来非常简单。如果我有一个名为 MYTABLE 的表,我应该能够执行此操作:
DataTable dt = Connection.GetSchema( SQLiteMetaDataCollectionNames.Columns, new string[] { null, null, "MYTABLE", null });
问题是,虽然我确实得到了一个 DataTable,但其中包含所有错误的信息。具体来说,这是我为 MYTABLE 假定的列返回的内容:
- [0] {TABLE_CATALOG} object {System.Data.DataColumn}
- [1] {TABLE_SCHEMA} object {System.Data.DataColumn}
- [2] {TABLE_NAME} object {System.Data.DataColumn}
- [3] {COLUMN_NAME} 对象 {System.Data.DataColumn}
- [4] {COLUMN_GUID} 对象 {System.Data.DataColumn}
- [5] {COLUMN_PROPID} 对象 {System.Data.DataColumn}
- [ 6] {ORDINAL_POSITION} 对象 {System.Data.DataColumn}
- [7] {COLUMN_HASDEFAULT} 对象 {System.Data.DataColumn}
- [8] {COLUMN_DEFAULT} 对象 {System.Data.DataColumn}
- [9] {COLUMN_FLAGS} 对象 {System .Data.DataColumn}
- [10] {IS_NULLABLE} 对象 {System.Data.DataColumn}
- [11] {DATA_TYPE} 对象 {System.Data.DataColumn}
- [12] {TYPE_GUID} 对象 {System.Data.DataColumn}
- [13] {CHARACTER_MAXIMUM_LENGTH} 对象 {System.Data.DataColumn}
- [14] {CHARACTER_OCTET_LENGTH} 对象 {System.Data.DataColumn}
- [15] {NUMERIC_PRECISION} 对象 {System.Data.DataColumn}
- [16] {NUMERIC_SCALE} 对象 {System.Data .DataColumn}
- [17] {DATETIME_PRECISION} 对象 {System.Data.DataColumn}
- [18] {CHARACTER_SET_CATALOG} 对象 {System.Data.DataColumn}
- [19] {CHARACTER_SET_SCHEMA} 对象 {System.Data.DataColumn}
- [20] {CHARACTER_SET_NAME } 对象 {System.Data.DataColumn}
- [21] {COLLATION_CATALOG} 对象 {System.Data.DataColumn}
- [22] {COLLATION_SCHEMA} 对象 {System.Data.DataColumn}
- [23] {COLLATION_NAME} 对象 {System.Data.DataColumn }
- [24] {DOMAIN_CATALOG} 对象 {System.Data.DataColumn}
- [25] {DOMAIN_NAME} 对象 {System.Data.DataColumn}
- [26] {DESCRIPTION} 对象 {System.Data.DataColumn}
- [27] {PRIMARY_KEY} 对象{System.Data.DataColumn}
- [28] {EDM_TYPE} 对象 {System.Data.DataColumn}
- [29] {AUTOINCRMENT} 对象 {System.Data.DataColumn}
- [30] {UNIQUE} 对象 {System.Data.DataColumn}
可以有人告诉我我在这里做错了什么吗?
I'm using SQLite.NET to access my databases, and in one particular case, I need to get a table schema because it's application-specific.
I've been looking through the SQLite.NET forum and google, and it seems very straightforward. If I have a table called MYTABLE, I should be able to do this:
DataTable dt = Connection.GetSchema( SQLiteMetaDataCollectionNames.Columns, new string[] { null, null, "MYTABLE", null });
The problem is that, although I do get a DataTable back, it's got all of the wrong information in it. Specifically, this is what I get back for the supposed columns of MYTABLE:
- [0] {TABLE_CATALOG} object {System.Data.DataColumn}
- [1] {TABLE_SCHEMA} object {System.Data.DataColumn}
- [2] {TABLE_NAME} object {System.Data.DataColumn}
- [3] {COLUMN_NAME} object {System.Data.DataColumn}
- [4] {COLUMN_GUID} object {System.Data.DataColumn}
- [5] {COLUMN_PROPID} object {System.Data.DataColumn}
- [6] {ORDINAL_POSITION} object {System.Data.DataColumn}
- [7] {COLUMN_HASDEFAULT} object {System.Data.DataColumn}
- [8] {COLUMN_DEFAULT} object {System.Data.DataColumn}
- [9] {COLUMN_FLAGS} object {System.Data.DataColumn}
- [10] {IS_NULLABLE} object {System.Data.DataColumn}
- [11] {DATA_TYPE} object {System.Data.DataColumn}
- [12] {TYPE_GUID} object {System.Data.DataColumn}
- [13] {CHARACTER_MAXIMUM_LENGTH} object {System.Data.DataColumn}
- [14] {CHARACTER_OCTET_LENGTH} object {System.Data.DataColumn}
- [15] {NUMERIC_PRECISION} object {System.Data.DataColumn}
- [16] {NUMERIC_SCALE} object {System.Data.DataColumn}
- [17] {DATETIME_PRECISION} object {System.Data.DataColumn}
- [18] {CHARACTER_SET_CATALOG} object {System.Data.DataColumn}
- [19] {CHARACTER_SET_SCHEMA} object {System.Data.DataColumn}
- [20] {CHARACTER_SET_NAME} object {System.Data.DataColumn}
- [21] {COLLATION_CATALOG} object {System.Data.DataColumn}
- [22] {COLLATION_SCHEMA} object {System.Data.DataColumn}
- [23] {COLLATION_NAME} object {System.Data.DataColumn}
- [24] {DOMAIN_CATALOG} object {System.Data.DataColumn}
- [25] {DOMAIN_NAME} object {System.Data.DataColumn}
- [26] {DESCRIPTION} object {System.Data.DataColumn}
- [27] {PRIMARY_KEY} object {System.Data.DataColumn}
- [28] {EDM_TYPE} object {System.Data.DataColumn}
- [29] {AUTOINCREMENT} object {System.Data.DataColumn}
- [30] {UNIQUE} object {System.Data.DataColumn}
Can anyone tell me what I've done wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQLiteConnection.GetSchema
很可能已损坏;大多数程序不需要此功能。您可以通过执行
PRAGMA table_info(MYTABLE)
命令来获取所需内容;您应该获得一个每列一行的数据读取器。It's quite possible that
SQLiteConnection.GetSchema
is broken; most programs do not need this functionality.You can get what you need by executing a
PRAGMA table_info(MYTABLE)
command; you should get a data reader with one row for each column.以下是如何使用
PRAGMA table_info(tableName)
按照 Stephen Cleary 的建议检查指定表中是否存在指定列。Here is an example of how to use the
PRAGMA table_info(tableName)
as suggested by Stephen Cleary to check if a specified column exists in a specified table.