【发布时间】:2019-05-01 08:24:18
【问题描述】:
问题是查询返回除了'id'之外的所有列
我使用 fts4,在文档中它说:
启用 FTS 的表始终使用 INTEGER 类型的主键,并且 列名“rowid”。如果您的 FTS 表支持的实体定义了一个 主键,它必须使用该类型和列名。
这是我的实体类:
@Fts4
@Entity(tableName = "projects")
public class Project {
@ColumnInfo(name = "rowid")
@PrimaryKey(autoGenerate = true)
private int id;
private String name;
@ColumnInfo(name = "start_date")
private String startDate;
@ColumnInfo(name = "end_date")
private String endDate;
private String description;
@ColumnInfo(name = "icon_path")
private String iconPath;
private long budget;
public Project(String name, String startDate, String endDate, String description, String iconPath, long budget) {
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.description = description;
this.iconPath = iconPath;
this.budget = budget;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getIconPath() {
return iconPath;
}
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
public long getBudget() {
return budget;
}
public void setBudget(long budget) {
this.budget = budget;
}
这是我的简单查询:
@Query("SELECT * FROM projects")
public LiveData<List<Project>> getAllProjectsI);
我收到警告:
app.aarsham.projeno.data.Model.Project 有一些字段 [rowid] 查询不返回。如果它们不应该被阅读 从结果中,您可以使用 @Ignore 注释标记它们。你可以 通过使用注释方法来抑制此警告 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)。返回的列 查询:名称、开始日期、结束日期、描述、图标路径、预算。 app.aarsham.projeno.data.Model.Project 中的字段:rowid、name、 开始日期、结束日期、描述、图标路径、预算。
还有一个错误:
查询返回的列中没有字段 [id] app.aarsham.projeno.data.Model.Project 即使它们被注释 作为非空或原始。查询返回的列: [名称、开始日期、结束日期、描述、图标路径、预算]
有人可以帮忙吗?
【问题讨论】:
-
从@Fts4项目类中移除
-
我遇到了同样的问题,从实体中删除
rowid列解决了该错误。希望对您有所帮助。 -
不知道您实际使用 FTS 时该怎么办?因为我收到了同样的警告......
标签: android sqlite android-room fts4