繁体   English   中英

尝试双引号转义表名时,PRAGMA table_info不返回双引号转义列名的信息

[英]PRAGMA table_info not returning info of double quote escaped column name when tried on double quote escaped table name

我有一个表,其名称以双引号转义(“表”)
它有一列也用双引号转义(“ 03/06/17”)

当我做表格信息时

table = "\"Table\"";
column = "\"03/06/17\"";
Cursor res = mDB.rawQuery("PRAGMA table_info("+table+")",null);
int value = res.getColumnIndex(column);

if(value == -1)
{
    isExist = false;
}

它总是返回-1。

但是当我执行普通查询时,我得到了该列。

    table = "\"Table\"";
    column = "03/06/17";
    Cursor cursor = mDB.query(table,null,
            null,null,null,null,null);
    int colIndex = 0;
    int colCount = cursor.getColumnCount();
    cursor.moveToFirst();
    while(colCount-- != 0) {

        if(column.equals(cursor.getColumnName(colIndex)))
            return true;

        colIndex++;
    }

然后使用

    table = "\"Table\"";
    column = "\"03/06/17\"";
    final String DB_ADD_COLUMN_STATEMENT_TABLE_SHOP_NAME =
                "ALTER TABLE "+ table + " ADD COLUMN "+ column + " FLOAT";
    mDB.execSQL(DB_ADD_COLUMN_STATEMENT_TABLE_SHOP_NAME);

table_info PRAGMA返回的数据中没有指定任何列。 光标中的每一行代表表中的一列,请看一下示例数据, table_info命令为表create table one(id, field1, field2 text, field3 unique);返回create table one(id, field1, field2 text, field3 unique);

cid         name        type        notnull     dflt_value  pk        
----------  ----------  ----------  ----------  ----------  ----------
0           id                      0                       0         
1           field1                  0                       0         
2           field2      text        0                       0         
3           field3                  0                       0         

因此,如果要查找名称为03/06/17的列的详细信息,则需要枚举游标并检查其name值是否等于03/06/17

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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