0

我已经调试了代码,似乎 sqlite 查询停止了 AsynkTask 线程:

    Log.d(LOG_TAG, "Getting params");
Cursor c = null;
try {
  String[] queryParams = new String[]{String.valueOf(commandQueueId), String.valueOf(DIRECTION_OUT)};
  // ↓↓↓ STOPPING HERE ↓↓↓
  c = dataSource.query(TABLE_USER_COMMAND, "queue_id = ? AND direction = ? AND _id > " + fromId, queryParams);

  Log.d(LOG_TAG, "After query");
  if (c.moveToFirst()) {
    UserCommand command;
    do {
      // Something with cursor
    } while (c.moveToNext());
  }

} catch (Exception e) {
  Log.e(LOG_TAG, "Error while querying", e);
} finally {
  Log.d(LOG_TAG, "Finnaly executed");
  if (null != c)
    c.close();
}

LogCat 只显示“获取参数”字符串,然后什么都没有(没有错误或任何东西)。在 AsyncTask 中执行的代码,dataSource 对象的所有方法都同步了。在 UI 线程查询中效果很好。会是什么?

4

3 回答 3

0

you are Not Passing Anything with _id inside your condition

"queue_id = ? AND direction = ? AND _id > "

it should be like

"queue_id = ? AND direction = ? AND _id > 1(or may other integer parameter)" + fromId, queryParams

Hope it will Help

于 2013-02-09T12:09:14.583 回答
0

我认为问题在于您试图在查询字符串中包含 _id 参数(fromId)。所以查询函数可能无法构建查询字符串

"queue_id = ? AND direction = ? AND _id > " + fromId

相反,您应该将 fromId 添加到 selectionArgs (queryParams)。创建一个包含您的 queryParams 和 fromId 的字符串数组。然后它应该工作。

String[] queryParams = new String[]{String.valueOf(commandQueueId), String.valueOf(DIRECTION_OUT), String.valueOf(fromId)};
c = dataSource.query(TABLE_USER_COMMAND, "queue_id = ? AND direction = ? AND _id > ? ", queryParams ); //queryParams which include your fromId
于 2013-02-09T12:49:52.067 回答
0

dataSource 对象已同步所有方法

当心死锁!尝试仅同步您的写入方法(插入、删除、更新)和读取方法(查询),因为在读取它们时没有更改数据的风险 PS:我知道问题有点老了,以防其他人正在阅读它。

于 2013-05-07T16:21:00.517 回答