gpt4 book ai didi

android - ContentProvider 与 SQlite : Same query different result

转载 作者:行者123 更新时间:2023-11-30 02:48:43 26 4
gpt4 key购买 nike

我有一个 ContentProvider,它在调试中使用自定义 CursorFacory 来打印 SQL 查询(用于调试)。

某个查询返回 0 行,而我知道应该包含一些行。所以我从我的日志中复制了查询,替换了绑定(bind)值并在设备上的 sqlite3 shell 中运行它并获得了正确的结果。

查询代码

cr.query (contentUri, 
Projection.columns,
FeedColumns.FEED_TYPE + "=? AND " +
FeedColumns.SUB_TYPE + "=? AND " +
ProfileUpdateFeedItem.UPDATED_FIELD + "=? AND " +
FeedColumns.IS_NOTIFIED + "=?",
new String[] {FeedType.USER, // 2
WallPostData.WallPostType.PROFILE_UPDATE, // 1
ProfileUpdateData.ProfileField.STATUS, // 0
SQLBoolean.FALSE // 0
},
FeedColumns.CREATED + " ASC");

来自日志:

07-04 12:48:51.339    4067-4314/com.redacted.android D/DATABASE﹕ QUERY: SQLiteQuery: SELECT DISTINCT id, sender, data_1, data_2, photo, feed_type, sub_type, created, expiry, updated, comment_count, comment_unread, reaction_count, reaction_unread, sender_name, sender_photo, _id FROM wall WHERE feed_type=? AND sub_type=? AND data_1=? AND is_notified=? ORDER BY created ASC LIMIT 100

在设备上:

Enter SQL statements terminated with a ";"
sqlite> SELECT DISTINCT id, sender, data_1, data_2, photo, feed_type, sub_type, created, expiry, updated, comment_count, comment_unread, reaction_count, reaction_unread, sender_name, sender_photo, _id FROM wall WHERE feed_type=2 AND sub_type=1 AND data_1=0 AND is_notified=0 ORDER BY created ASC LIMIT 100;
53b702b827d7482062f52b03|a7e759d78abe4bfa97045ce49a24ab57|0|Educ||2|1|1404502712279|1404761912325|1404502712279|||||Luke Skywalker|pr/e5c2c0398b267f93683c80dc5009722e|49

但是,ContentProvider 不同意,cursor.getCount() 返回 0。

知道为什么会这样吗?

feed_typesub_typeis_notifiedINTEGER 列。

data_1 是一个 BLOB,它为符合此查询条件的任何行存储一个整数,但存储字符串 用于此表中可能包含的其他类型的数据。

最佳答案

当您在 shell 中运行时,我很惊讶您会得到任何行。 blob 数据类型可能无法为您正确转换键控值。通常,数据库 API 需要一个特殊函数来设置和检索 blob 值。

关于android - ContentProvider 与 SQlite : Same query different result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24580317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com