- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一个 SQL 菜鸟,不明白为什么我的语句的行为方式如此。它在 Android Room DAO 中使用并返回不需要的结果。
我在两个表中有这个示例数据:
我有这样的声明:
@Transaction
@Query("Select Distinct Category.* " +
"from Category " +
"inner join Items on Category.ID = Items.Category " +
"where IsExcluded = 0 " +
"order by lower( Category.Name ) asc")
LiveData<List<CatViewWithItemList>> getCatViewWithItemListGlobal();
public class CatViewWithItemList {
@Embedded
public Cat myCat;
@Relation(parentColumn = "ID",
entityColumn = "Category") public List<ItemS> ItemList;
@TypeConverter
public Boolean fromInt(int value) {
return value == 0 ? false : true;
}
@TypeConverter
public int toInt(Boolean bValue) {
if (bValue == false) {
return 0;
} else {
return 1;
}
}
最佳答案
我相信这要么是由于您的死简单转换器,要么可能是由于项目实体的定义方式(我使用了 bool 值 用于 排除了 并且它似乎在没有转换器的情况下工作正常)。
那是使用我的 Items Entity 版本:-
@Entity(foreignKeys = @ForeignKey(entity = Category.class,parentColumns = "id", childColumns = "category", onDelete = CASCADE))
public class Items {
@PrimaryKey(autoGenerate = true)
private long id;
private String category;
private boolean isexcluded;
public void setCategory(String category) {
this.category = category;
}
public void setId(long id) {
this.id = id;
}
public void setIsexcluded(boolean isexcluded) {
this.isexcluded = isexcluded;
}
public String getCategory() {
return this.category;
}
public long getId() {
return this.id;
}
public boolean isIsexcluded() {
return this.isexcluded;
}
}
@Dao
interface CategoryDAO {
@Query("SELECT * FROM Category")
List<Category> getAllcategories();
@Query("SELECT DISTINCT Category.* " +
"FROM CATEGORY " +
"INNER JOIN ITEMS ON category.id = Items.category " +
"WHERE isexcluded = 0 " +
"ORDER BY lower(category.name)")
List<Category> getSpeacial();
@Query("SELECT DISTINCT Category.* " +
"FROM CATEGORY " +
"INNER JOIN ITEMS ON category.id = Items.category " +
"WHERE isexcluded = 0 " +
"ORDER BY lower(category.name)")
List<CatViewWithItemList> getSpeacial2();
@Insert
public long[] insertCategory(Category... Category);
}
new Thread(new Runnable() {
@Override
public void run() {
//mRoomDB.categoryDao().insertCategory(initialCategories());
//mRoomDB.itemsDAO().insertItem(initialItems());
List<Category> categoryList = mRoomDB.categoryDao().getAllcategories();
List<Items> itemsList = mRoomDB.itemsDAO().getAllItems();
for (Category c: categoryList) {
Log.d("CATEGORY","Category is " + c.getName() + " refrence is " + c.getId());
}
for (Items i: itemsList) {
Log.d("ITEM","Item is " + i.getId() + " Category reference is " + i.getCategory() + " Is Excluded is " + Boolean.toString(i.isIsexcluded()));
}
List<Category> categoryList2 = mRoomDB.categoryDao().getSpeacial();
for (Category c: categoryList2) {
Log.d("CATEGORY2","Category is " + c.getName() + " reference is " + c.getId());
}
List<CatViewWithItemList> catViewWithItemLists = mRoomDB.categoryDao().getSpeacial2();
for (CatViewWithItemList cvwil: catViewWithItemLists) {
Log.d("CATVIEWITEM","Category = " + cvwil.myCat.getId() + " ID = " + cvwil.ItemList.get(0).getId() + " IsExcluded = " + Boolean.toString(cvwil.ItemList.get(0).isIsexcluded()));
}
}
}).start();
public class CatViewWithItemList {
@Embedded
public Category myCat;
@Relation(parentColumn = "id",
entityColumn = "category")
public List<Items> ItemList;
}
2018-12-19 21:47:05.376 2109-2125/? D/CATEGORY: Category is firstname refrence is a
2018-12-19 21:47:05.377 2109-2125/? D/CATEGORY: Category is secondname refrence is b
2018-12-19 21:47:05.377 2109-2125/? D/CATEGORY: Category is thridname refrence is c
2018-12-19 21:47:05.377 2109-2125/? D/ITEM: Item is 1 Category reference is a Is Excluded is false
2018-12-19 21:47:05.377 2109-2125/? D/ITEM: Item is 2 Category reference is c Is Excluded is false
2018-12-19 21:47:05.377 2109-2125/? D/ITEM: Item is 3 Category reference is null Is Excluded is false
2018-12-19 21:47:05.377 2109-2125/? D/ITEM: Item is 4 Category reference is b Is Excluded is false
2018-12-19 21:47:05.377 2109-2125/? D/ITEM: Item is 5 Category reference is b Is Excluded is true
2018-12-19 21:47:05.378 2109-2125/? D/ITEM: Item is 6 Category reference is null Is Excluded is true
2018-12-19 21:47:05.379 2109-2125/? D/CATEGORY2: Category is firstname reference is a
2018-12-19 21:47:05.380 2109-2125/? D/CATEGORY2: Category is secondname reference is b
2018-12-19 21:47:05.380 2109-2125/? D/CATEGORY2: Category is thridname reference is c
2018-12-19 21:47:05.382 2109-2125/? D/CATVIEWITEM: Category = a ID = 1 IsExcluded = false
2018-12-19 21:47:05.382 2109-2125/? D/CATVIEWITEM: Category = b ID = 4 IsExcluded = false
2018-12-19 21:47:05.382 2109-2125/? D/CATVIEWITEM: Category = c ID = 2 IsExcluded = false
cvwil.ItemList.get(0).isIsexcluded()
幸运的是 4 出现在 5 之前,所以 isexcluded 显示为假。
SELECT *
FROM Items
JOIN Category ON Items.category = category.id
WHERE Items.isexcluded = 0
ORDER BY category.name ASC;
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/CATEGORY: Category is firstname Category ID is a
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/CATEGORY: Category is secondname Category ID is b
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/CATEGORY: Category is thirdname Category ID is c
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/CATEGORY: Category is fourthname Category ID is d
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 1 Category reference is a Is Excluded is false
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 2 Category reference is c Is Excluded is false
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 3 Category reference is null Is Excluded is false
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 4 Category reference is b Is Excluded is false
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 5 Category reference is b Is Excluded is true
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 6 Category reference is null Is Excluded is true
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 7 Category reference is d Is Excluded is true
2018-12-20 21:39:56.971 9136-9160/so53839431.so53839431roomrelationship D/ITEM: Item is 8 Category reference is d Is Excluded is false
2018-12-20 21:39:56.972 9136-9160/so53839431.so53839431roomrelationship D/ITEMWITHCAT: Item id =1 Category reference is a Is Excluded is false Referenced Category is a Referenced Category name is firstname
2018-12-20 21:39:56.972 9136-9160/so53839431.so53839431roomrelationship D/ITEMWITHCAT: Item id =2 Category reference is c Is Excluded is false Referenced Category is c Referenced Category name is thirdname
2018-12-20 21:39:56.972 9136-9160/so53839431.so53839431roomrelationship D/ITEMWITHCAT: Item id =4 Category reference is b Is Excluded is false Referenced Category is b Referenced Category name is secondname
2018-12-20 21:39:56.972 9136-9160/so53839431.so53839431roomrelationship D/ITEMWITHCAT: Item id =8 Category reference is d Is Excluded is false Referenced Category is d Referenced Category name is fourthname
关于sql - Android Room Embedded Relation 忽略 SQL where 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839431/
即使从 androidx.room.Room 导入,Room.databaseBuilder() 也无法找到 Room 依赖项。 我为数据库制作了一个不同的 Kotlin 库,并在 Room 的 gr
我正在尝试迁移我们的项目以使用 Room,顺便说一句,我认为这是向前迈出的一大步。 我有以下结构: public class Entity extends BaseObservable { @
Here是房间数据库的官方文档。它包含以下代码 val db = Room.databaseBuilder( applicationContext, A
Here是房间数据库的官方文档。它包含以下代码 val db = Room.databaseBuilder( applicationContext, A
我有一张供用户使用的表。用户创建一个类别,然后将 Youtube 视频分配到该类别。我目前有一个用户表、类别表(用户 ID 外键)和 youtubevideo 表(用户 ID 外键、类别外键)。 我目
拥有三张 table 的 Android Room timestamp , index , details ,并且这三个都有 @PrimaryKey @ColumnInfo(name = "id")
让我们举一个基本的例子 用于存储用户的表 @Entity (tableName="users") class UsersEntity( @PrimaryKey val id var
想确认是否可以将实体 bean 绑定(bind)到表的部分列? 例子: 表“A”有列 id, col1, col2, col3, col4, col5, ... , col10 但是我只需要 id、c
问题 双向数据绑定(bind)允许您使用来自对象的数据自动填充 UI 组件,然后在用户编辑这些 UI 组件时自动更新对象。 当用户编辑 UI 组件时,有没有办法不仅自动更新内存中的对象,而且自动更新/
我在 Android Room 中使用可观察查询来触发更新,最终在底层数据发生变化时改变 UI。 有时这些查询涉及多个表,有时用户执行将新值插入到这些表中的操作。插入通常一个接一个地快速完成(即在不到
我想知道点击新房间后如何离开房间 我的页面是这样的。 左侧列表来自MySQL服务器,它获取我的聊天列表。每个房间名称都有 id 值,即房间名称。并且它还有onclick函数可以在客户端使用函数。 当我
我正在尝试将此模块化项目升级到最新的依赖项,但 gradle 构建失败并显示 could not resolve androidx.room:room-runtime:2.4.2我已经包含了maven
在使用 Kotlin Coroutines Flow、Room 和 Live Data 时,我面临着一个非常奇怪的行为。每当我关闭我的设备大约 5-10 秒然后重新打开它时,协程流程就会重新运行而没有
我正在与一位同事讨论我们部署的一款软件遇到的问题,他提到这与一段时间内预订房间的概念问题有何相似之处,算法应该输出房间需要最少开关的预订(因此,例如,最佳解决方案可能是在一个房间停留 3 天,其余时间
如何使用 Room Persistence 库“创建触发器” CREATE TRIGGER IF NOT EXISTS delete_till_10 INSERT ON user WHEN (sel
你如何在 Android Room 中使用 List 的 我有一个表实体,我想通过 Android Room 将其保存在我的 SQLDatabase 中。我已经按照我在网上可以做得很好的一切,并且没有
我正在研究可以在图像上绘制矩形的东西。它工作得很好,因为 JavaFX 很容易,但我遇到了一个我似乎不理解的小问题。 我一直使用 for (object b : ArrayList) ,但从未发生过这
我对java完全陌生。我花了几个小时寻找这个问题的解决方案,但每个答案都涉及传递参数或使用 void,但在这种情况下我不会这样做。 我有两个 java 文件,一个用于 Room 类,一个用于 Tour
我正在创建一个聊天网站,我正在使用 Strophe.js 和 Strophe.muc.js 插件。单人聊天功能运行良好,但我也不想实现群聊功能,用户可以在其中创建房间并邀请其他用户加入他们的房间。使用
按照教程设置 Room 持久性库时,我在 Android 设备上进行测试时遇到了这个错误。 java.lang.RuntimeException:找不到 PackageName.AppDatabase
我是一名优秀的程序员,十分优秀!