gpt4 book ai didi

android - CursorLoader - 两个表连接查询?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:30:37 25 4
gpt4 key购买 nike

我有两个 1:1 关系的表,我正在使用内容提供程序和游标加载器。

我将如何进行连接查询以使用游标加载器?我可以在内容提供程序中使用 rawSql 以某种方式破解它,但我无法在游标加载器构造函数中进行操作。

非常感谢!

private static final String CREATE_TABLE_ARTICLES = "create table "
+ TABLE_ARTICLES + "("
+ COLUMN_ARTICLE_ID + " integer primary key autoincrement, "
+ COLUMN_URL + " text not null unique, "
+ COLUMN_TITLE + " text not null, "
+ COLUMN_PRICE + " text not null, "
+ COLUMN_ADDED + " text not null, "
+ COLUMN_IMG_URL + " text);";

private static final String CREATE_TABLE_ARTICLE_DETAIL = "create table "
+ TABLE_ARTICLE_DETAILS + "("
+ COLUMN_ARTICLE_DETAIL_ID + " integer primary key autoincrement, "
+ COLUMN_DESC + " text not null, "
+ COLUMN_LOCALITY + " text, "
+ COLUMN_TYPE + " text not null, "
+ COLUMN_SELLER + " text not null, "
+ COLUMN_SELLER_PHONE + " text, "
+ COLUMN_IMAGE_COUNT + " integer default 0, "
+ COLUMN_ARTICLE + " integer, foreign key (" + COLUMN_ARTICLE + ") references " + TABLE_ARTICLES + "(" + COLUMN_ARTICLE_ID + "));";

最佳答案

实际上,您不必使用自定义任务加载器。简而言之,一种解决方案是创建 Uri“content://AUTHORITY/TableArticlesWithDetail”。然后在您的内容提供程序中,检查该 Uri 并执行原始 SQL 来执行连接。

参见 how to use join query in CursorLoader when its constructor does not support it了解详情。

关于android - CursorLoader - 两个表连接查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14076540/

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