在Android Room中,我有一个if (txt.SelectionStart == 0 || txt.SelectionStart == 2 || txt.SelectionStart == 4)
{
txt.InputType = InputTypes.ClassText | InputTypes.TextFlagCapCharacters;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) });
}
else if (txt.SelectionStart == 1 || txt.SelectionStart == 3 || txt.SelectionStart == 5)
{
txt.InputType = InputTypes.ClassNumber;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) });
}
查询,其中我将列值SELECT
分配给了另一列:component_category.name
经过几次试验,我通过以下查询成功完成了此操作:
component.component_category_name
但是我想知道是否有更有效的方法来减小查询的大小。
我尝试了以下操作:
@Query("SELECT component.id, rack_id, component_category_id, component.name, component.component_category_name, code, component.img_path, " +
" (SELECT COUNT(component.id) " +
" FROM component " +
" WHERE component.rack_id = :rackID) as count, " +
" (SELECT name " +
" FROM component_category " +
" WHERE component_category.id == component_category_id) as component_category_name " +
"FROM component " +
"INNER JOIN component_category ON component_category.id = component.component_category_id " +
"WHERE component.rack_id == :rackID ORDER BY component.name ASC")
LiveData<List<Component>> getRackComponents(long rackID);
创建该试用的,但该查询的结果中@Query("SELECT component.id, rack_id, component_category_id, component.name, component.component_category_name AS [component.component_category_name], code, component.img_path, " +
" (SELECT COUNT(component.id) " +
" FROM component " +
" WHERE component.rack_id = :rackID) as count " +
"FROM component " +
"INNER JOIN component_category ON component_category.id = component.component_category_id " +
"WHERE component.rack_id == :rackID AND component_category.id == component.component_category_id ORDER BY component.name ASC")
LiveData<List<Component>> getRackComponents(long rackID);
是component.category_name
。