【发布时间】:2015-02-02 21:16:13
【问题描述】:
我正在尝试编写这样的 SQL 查询
SELECT *
FROM TABLE_USER
WHERE theUser = userID;
但是 Android 使用 Cursor,我不确定我这样做是否正确。有人可以确认吗?这是光标查询函数的标题:
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
selection:一个过滤器,声明要返回哪些行,格式化为 SQL WHERE 子句(不包括 WHERE 本身)。传递 null 将返回给定表的所有行。
这是我的代码:
public ArrayList<Goal> getAllGoals(User user) {
int currentUserID = user.getUserID();
String theUser = Integer.toString(currentUserID);
String[] columns = new String[] {userID, goal, activityType, target_steps, completed_steps};
Cursor c = db.query(TABLE_GOAL, columns, theUser, null, null, null, null);
ArrayList<Goal> allGoals = new ArrayList<Goal>();
while(c.moveToNext()){
c.getInt(currentUserID);
c.getInt()
}
c.close();
return allGoals;
}
【问题讨论】:
-
您忘记了第四个参数,它是您的参数参数。应该类似于
userId。 -
谢谢,根据您的指导找到了我的答案
标签: android database sqlite cursor