sqlite rawquery未执行

时间:2019-05-22 08:50:42

标签: android sqlite

要检查索引的正确用法,我使用了解释性的rawquery语句。

在我的测试设备上,它可以正常运行,但是一个QA测试人员遇到了无法执行并抛出

的问题
  

SQLiteException:未知错误(Sqlite代码100),(OS错误-2:No   这样的文件或目录)

同一数据库已成功用于常规查询,且向下几行。

SQLiteDatabase database = databaseOpenHelper.getReadableDatabase();
try {
    //create a query plan
    StringBuilder queryPlanStatementBuilder = new StringBuilder(" QUERY PLAN SELECT ");
    for (int i = 0; i < selectionColumns.size(); i++) {
        queryPlanStatementBuilder.append(selectionColumns.get(i));
        if (i < selectionColumns.size() - 1) {
            queryPlanStatementBuilder.append(',');
        }
    }
    queryPlanStatementBuilder
        .append(" FROM ")
        .append(sqlTableName);
    if (selection != null) {
        queryPlanStatementBuilder
            .append(" WHERE ")
            .append(selection);
    }
    cursor = database.rawQuery(queryPlanStatementBuilder.toString(), selectionArgs);
    StringBuilder resultBuilder = new StringBuilder();
    if (cursor != null && cursor.moveToNext()) {
        for (int i = 0; i < cursor.getColumnCount(); i++) {
            resultBuilder.append(cursor.getColumnName(i)).append(':').append(cursor.getString(i)).append(", ");
        }
    }
    Logger.t(LOG_TAG, queryPlanStatementBuilder.toString());
    Logger.t(LOG_TAG, "EXPLAIN Result: " + resultBuilder.toString());
} catch (Exception e) {
    Logger.e(LOG_TAG, "getFilteredItems: Error in explain query", e);
} finally {
    if (cursor != null) {
        cursor.close();
    }
}
[...]
//This code executes without issues!
cursor = database.query(sqlTableName, selectionColumns.toArray(new String[0]), selection, selectionArgs, null, null, null);

日志中正确的输出如下所示:

  

EXPLAIN结果:selectid:0,order:0,from:0,详细信息:SEARCH TABLE   tbl_1837703722_InventoryMain使用索引   idx_1837703722_InventoryMain_ExternalIDAndCompanyCode   (col_EXTENRAL_ID =?AND col_COMPANY_CODE =?),

0 个答案:

没有答案