Room error: is there no alternative at the entrance?
I'm trying to update a table using @Query annotation of room library, below is my code (in Dao frontend):
@Query("UPDATE table_name SET table_name.col1 = :val1 WHERE table_name.col2 = :val2")
void updateValue(long val1, long val2);
End the error line as shown below:
Error:(11, 10) error: no viable alternative at input 'UPDATE table_name SET table_name.'
Here is the entity class:
@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;
}
}
What's wrong with my code?
+3
source to share
1 answer
Try changing your operator to:
UPDATE table_name SET col1 = :val1 WHERE col2 = :val2.
The error message makes it feel like "Room" is being disconnected via the prefix.
This is a bug in the room, at least through 1.0.0-alpha8
. Track this issue to see when it gets fixed.
This is actually invalid SQLite syntax as it turns out . Table prefixes are in columns in the statements SELECT
, not UPDATE
statements .
+4
source to share