【问题标题】:How to get column Data Type from a row of Sqlite3 db - Objective C如何从一行 Sqlite3 db 中获取列数据类型 - Objective C
【发布时间】:2016-06-30 18:46:13
【问题描述】:
for (int i=0; i< sqlite3_column_count(selectStatement); i++)                    
{

    int intValue = 0; 
    const char *strValue;
    switch (sqlite3_column_type(selectStatement,i)) 
    {
    }

}

如何从一行Sqlite3 db中获取列数据类型

Android 等效代码,其中我有全局光标对象并且工作正常:

public Object get(String name, QueryDbType type) throws Exception {

    Object retult = null;
    int index = cursor.getColumnIndex(name);
    switch (type) {
    case Text:
        retult = cursor.getString(index);
        break;
    case Int:
        retult = cursor.getInt(index);
        break;

    default:
        retult = cursor.getString(index);
        break;
    }
    return retult;
}

【问题讨论】:

  • 不容易; Java 是面向对象的,并且具有良好集成的 sqlite3 包装器。基本的 sqlite3 API 是 C 并且 C 不是面向对象的。因此,您正在查看 union 或类似的东西,但是您怎么还不知道列类型?
  • sqlite3_column_type() 已经做了你想做的事。有什么问题?
  • 他想要一个 C 变种机制来捕获列值。
  • 我有一个表格,其中一些字段是 TEXT 和一些罕见的 BLOB,但是当我检查 sqlite3_column_type 时,我总是得到 3。3 表示文本。

标签: ios iphone sqlite column-types


【解决方案1】:

SQLite 是“无类型”的。这意味着您可以在任何表的任何列中存储任何类型的数据,而不管该列的声明数据类型如何。你可以找到更多信息here.

但是,如果您想获取有关列的声明数据类型的信息,您可以使用 pragma table_info(table_name) 来实现。

例如。

pragma table_info(Setting);

然后,您可以遍历返回的结果集并检查您要检查的数据类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 2011-10-01
    • 2011-11-27
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多