在SQLiteDatabase.query()中使用String [] selectionArgs

Ben*_*ebe 49 android android-cursor android-sqlite

如何使用String[] selectionArgsSQLiteDatabase.query()?我希望我可以把它设置为null,因为我没有用它.我只是尝试将数据库中的整个未排序表加载到Cursor.有关如何实现这一目标的任何建议?

Gal*_*aim 197

selectionArgs替换选择字符串中的任何问号.

例如:

String[] args = { "first string", "second@string.com" };
Cursor cursor = db.query("TABLE_NAME", null, "name=? AND email=?", args, null);
Run Code Online (Sandbox Code Playgroud)

至于你的问题 - 你可以使用null

  • 我不明白为什么这不是公认的答案..它简单明了,更好地回答了这个问题! (27认同)
  • @Mangusto,这是因为另一个给了OP他想要的答案,而不是他要求的答案. (5认同)
  • @Mangusto那里,那更好吗?:)我还没有完全活跃在这个网站上. (2认同)
  • @Mangusto。两年后再回来+1以标记正确答案 (2认同)

waq*_*lam 14

是的,您可以将所有参数设置为null,但表名除外.

例如:

Cursor cursor = db.query("TABLE_NAME", null, null, null, null, null, null);
Run Code Online (Sandbox Code Playgroud)

  • 对于downvoters:任何特定的downvoting原因? (2认同)