Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
Description
Version used: 1.0
Devices/Android versions reproduced on: all
I wasn't paying attention that I had a column name called "to" which is a SQL reserved keyword, but there was no problem at first and tables were created successfully and there was no problem until I decided to use @Relation to automatically fetch relation entities.
@Entity(tableName = "categories")
public class Category {
@PrimaryKey(autoGenerate = true)
public long id;
public String name;
}
@Entity(tableName = "topics", foreignKeys = @ForeignKey(entity = Category.class,
parentColumns = "id",
childColumns = "category_id",
onDelete = ForeignKey.CASCADE))
public class Topic {
@PrimaryKey(autoGenerate = true)
public long id;
@ColumnInfo(name = "category_id")
public long categoryId;
public String to;
}
public class CategoryWithTopics {
@Embedded
public Category category;
@Relation(parentColumn = "id", entityColumn = "category_id", entity = Topic.class)
public List<Topic> topics;
}
and in the DAO
@Transaction
@Query("SELECT * FROM categories")
List<CategoryWithTopics> getPerDiemDraftsWithItems();
This produces a compile time error "Error:(17, 24) error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (near "to": syntax error)"
It was a stupid mistake to name the column one of the SQL reserved keywords, but it was working without any problems when it's escaped when creating the table but looks like the query changed when using the Relation annotation and the reserved keywords won't work there.
It may be not solvable, but at least we can have a small lint check for column names to be non-reserved SQL keyword.
A project where this can be reproduced is attached