gpt4 book ai didi

android - 房间错误 : no viable alternative at input?

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

我正在尝试使用房间库的@Query 注释更新表,下面是我的代码(在 Dao 接口(interface)中):

@Query("UPDATE table_name SET table_name.col1 = :val1 WHERE table_name.col2 = :val2")
void updateValue(long val1, long val2);

完整的错误字符串如下:

Error:(11, 10) error: no viable alternative at input 'UPDATE table_name SET table_name.'

这是实体类:

@Entity(tableName = "table_name")
public class SampleTable {

@PrimaryKey
@ColumnInfo(name = "_id")
private Long Id;

@ColumnInfo(name = "col1")
private Long column1;

@ColumnInfo(name = "col2")
private Long column2;

public Long getId() {
return Id;
}

public void setId(Long id) {
Id = id;
}

public Long getColumn1() {
return column1;
}

public void setColumn1(Long column1) {
this.column1 = column1;
}

public Long getColumn2() {
return column2;
}

public void setColumn2(Long column2) {
this.column2 = column2;
}
}

我的代码有什么问题?

最佳答案

在这种情况下也可能发生此错误:

如果你传递的是一个列表,不要忘记添加括号将你的列表变量括起来,否则你会得到同样的错误:

@Query("select name from mytable where name in (:myList)")
LiveData<List<String>> findNames(List<String> myList);

关于android - 房间错误 : no viable alternative at input?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45575898/

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