Android Room数据库查询不返回id列

Ars*_*ham 5 sqlite android fts4 android-room

问题是查询返回除“ 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;
}
Run Code Online (Sandbox Code Playgroud)

这是我的简单查询:

@Query("SELECT * FROM projects")
public LiveData<List<Project>> getAllProjectsI);
Run Code Online (Sandbox Code Playgroud)

我收到警告:

app.aarsham.projeno.data.Model.Project具有查询未返回的某些字段[rowid]。如果不应从结果中读取它们,则可以使用@Ignore批注对其进行标记。您可以通过使用@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)注释该方法来禁止显示此警告。查询返回的列:名称,开始日期,结束日期,描述,icon_path,预算。app.aarsham.projeno.data.Model.Project中的字段:行ID,名称,开始日期,结束日期,描述,icon_path,预算。

和一个错误:

查询返回的列在app.aarsham.projeno.data.Model.Project中没有字段[id],即使它们被注释为非null或原始值也是如此。查询返回的列:[名称,开始日期,结束日期,描述,图标路径,预算]

有人可以帮忙吗?

jac*_*314 7

使用FTS时,rowid即使select *要选择所有行,也必须在查询中明确包括行“ ” 。

基本上,查询应该像 @Query("SELECT *, `rowid ` FROM projects")