I might have more then one filter being chosen on my database, so I would like to query the database for a cursor, then do a query on that cursor to return another one.
我可能在我的数据库中选择了多个过滤器,所以我想查询数据库中的游标,然后对该游标进行查询以返回另一个。
3 个解决方案
#1
4
You can't do a query on a cursor. A cursor is the result of a query. It is not the source of a query. You need to do a new query for the same place you got the original cursor, with new arguments that specify the new data set you want.
您无法对游标进行查询。游标是查询的结果。它不是查询的来源。您需要为原始游标所在的相同位置执行新查询,并使用指定所需新数据集的新参数。
#2
3
You have to use inner loop for filter record it is one of the option for you
你必须使用内部循环进行过滤记录,这是你的选择之一
for that you have to first fetch record in cursor1 and in a inner loop you can use value of 1st Cursor and query again for cursor2
因为你必须首先在cursor1和内部循环中获取记录,你可以使用1st Cursor的值并再次查询cursor2
EDIT
编辑
1) If you want particular columns then You can filter in db.query() method for example
1)如果你想要特定的列,那么你可以在db.query()方法中进行过滤
Cursor curTaskList = db.query("tablename", new String[]{"col1", "col2"}, null, null, null, null, null);
2) If you want Particular row then you can filter in db.query() method for example
2)如果你想要特殊行,那么你可以在db.query()方法中进行过滤
Cursor curTaskList = db.query("timebasedlist", null, "col1 = ? AND col2 = ?", new String[]{"val1", "val2"}, null, null, null);
so there is no need for query over cursor
所以不需要对游标进行查询
You can filter within a single query
您可以在单个查询中进行过滤
If your cursor has more than one row you can fetch row by row using loop
如果游标有多行,则可以使用循环逐行获取
#3
1
You could store the query as text and use them to create new cursors?
您可以将查询存储为文本并使用它们来创建新游标?
#1
4
You can't do a query on a cursor. A cursor is the result of a query. It is not the source of a query. You need to do a new query for the same place you got the original cursor, with new arguments that specify the new data set you want.
您无法对游标进行查询。游标是查询的结果。它不是查询的来源。您需要为原始游标所在的相同位置执行新查询,并使用指定所需新数据集的新参数。
#2
3
You have to use inner loop for filter record it is one of the option for you
你必须使用内部循环进行过滤记录,这是你的选择之一
for that you have to first fetch record in cursor1 and in a inner loop you can use value of 1st Cursor and query again for cursor2
因为你必须首先在cursor1和内部循环中获取记录,你可以使用1st Cursor的值并再次查询cursor2
EDIT
编辑
1) If you want particular columns then You can filter in db.query() method for example
1)如果你想要特定的列,那么你可以在db.query()方法中进行过滤
Cursor curTaskList = db.query("tablename", new String[]{"col1", "col2"}, null, null, null, null, null);
2) If you want Particular row then you can filter in db.query() method for example
2)如果你想要特殊行,那么你可以在db.query()方法中进行过滤
Cursor curTaskList = db.query("timebasedlist", null, "col1 = ? AND col2 = ?", new String[]{"val1", "val2"}, null, null, null);
so there is no need for query over cursor
所以不需要对游标进行查询
You can filter within a single query
您可以在单个查询中进行过滤
If your cursor has more than one row you can fetch row by row using loop
如果游标有多行,则可以使用循环逐行获取
#3
1
You could store the query as text and use them to create new cursors?
您可以将查询存储为文本并使用它们来创建新游标?