我在我的应用中添加了一些额外的搜索功能 - 经过测试,在Android 4.4.2上运行良好。
刚刚将我的设备更新到5.0,这个新的搜索功能不起作用,返回一个空光标。 (应用程序中的其他查询都可以在所有设备上正常工作,表明这是代码问题而不是数据问题。)
据我所知,从Android 4.4.2到Android 5.0,SQLite已从3.7.11更新到3.8.0,我希望这是此问题的原因。我看过changelog for SQLite 3.8.0并且没有任何东西可以引人注目(无论如何都是我未经训练的眼睛)。
以下是我的代码生成的问题:
SELECT
statuses.status AS status,
shelves.shelf_name AS shelf_name,
aisles.aisle_name AS aisle_name,
products.image_file_name_stored AS image_file_name_stored,
parent_companies.url AS url,
parent_companies.email AS email,
products.buy_url AS buy_url,
products_data.status_id AS status_id,
parent_companies.company_name AS company_name,
products.image_file_name AS image_file_name,
'(' || shelves.shelf_name || ')' AS suggest_text_2,
products._id AS suggest_intent_data_id,
products.product_name AS suggest_text_1,
parent_companies.tel AS tel,
products.product_name AS product_name,
products_data.notes AS notes,
products.priority AS priority,
products._id AS _id,
products_data.last_modified_on AS last_modified_on
FROM
products
INNER JOIN
parent_companies ON products.parent_company_id = parent_companies._id
INNER JOIN
shelves ON products.shelf_id = shelves._id
INNER JOIN
aisles ON shelves.aisle_id = aisles._id
INNER JOIN
products_data ON products._id = products_data.product_id
INNER JOIN
statuses ON products_data.status_id = statuses._id
WHERE
(shelves._id = ?)
ORDER BY
shelf_name ASC
我的selectionArgs = {"156"}
。
更新
现在,为了测试,我已将selection
字符串设置为null
,将selectionArgs
字符串[]设置为null
,现在光标充满结果 - 太多,当然因为不再有WHERE
条件。
所以,我的问题最终是这个......为什么让以下选择标准在Android 4.4.2(SQLite 3.7.11)中给出结果但在Android 5.0(SQLite 3.8.0)中没有结果?... < / p>
String selection = "shelves._id = ?";
String[] selectionArgs = {"156"};
...当然不是我试图将整数列(_id
)与字符串("156"
)进行比较? !
更新#2
使用有问题的查询,我介入调试器,在SQLiteQueryBuilder.java的第393行,然后sql String是......
“SELECT statuses.status AS status,shelves.shelf_name AS shelf_name, aisles.aisle_name AS aisle_name,products.image_file_name_stored AS image_file_name_stored,parent_companies.url AS url, parent_companies.email AS电子邮件,products.buy_url AS buy_url, products_data.status_id AS status_id,parent_companies.company_name AS company_name,products.image_file_name AS image_file_name,'('|| shelves.shelf_name || ')'AS suggest_text_2,products._id AS suggest_intent_data_id,products.product_name AS suggest_text_1, parent_companies.tel AS tel,products.product_name AS product_name, products_data.notes AS notes,products.priority AS priority, products._id AS _id,products_data.last_modified_on AS last_modified_on FROM products INNER JOIN parent_companies ON products.parent_company_id = parent_companies._id INNER JOIN货架 ON products.shelf_id = shelves._id INNER JOIN aisles ON shelves.aisle_id = aisles._id INNER JOIN products_data ON products._id = products_data._id INNER JOIN状态ON products_data.status_id = statuses._id WHERE(shelves._id =?)ORDER BY shelf_name ASC“
......看起来不错。我继续使用调试器来查看它出错的地方,但当我进入db.rawQueryWithFactory()
方法时,调试器似乎迷路了(它把我带到了注释行),所以我不确定实际问题可能是什么。
答案 0 :(得分:0)
我怀疑是对的。我刚刚尝试使用此代码修改selection
和selectionArgs
,现在所有内容都按预期工作:
if (selection != null && selectionArgs != null && selectionArgs.length == 1 && isNumeric(selectionArgs[0])) {
selection = selection.replace("?", selectionArgs[0]); // e.g., changes "shelves._id = ?" to "shelves._id = 156"
selectionArgs = null; // e.g., changes {"156"} to null
}