可以在创建表时,将所有列名和表名设置为小写,并在查询时使用LOWER函数将查询条件转换为小写,以实现对大小写不敏感的查询。
示例代码:
@Entity(tableName = "my_table") public class MyEntity { @PrimaryKey @ColumnInfo(name = "id") public int id;
@ColumnInfo(name = "name")
public String name;
}
// 将表名和列名设置为小写
@Dao
public interface MyDao {
@Query("SELECT * FROM my_table WHERE LOWER(name) = LOWER(:name)")
LiveData> getEntitiesByName(String name);
}