SQLiteDatabase中的query方法里的各个参数是干什么的?

OlymHuang 2012-02-28 04:09:32
小弟在自学Android时,在SQLite这里遇到这个问题
其中有段代码如下,是一个查询的语句,就是不明白query方法里的各个参数分别是干什么的,请指教!

dbInstance.query(DB_TABLENAME,
new String[]{"_id","name","mobilephone","officephone",
"familyphone","address","othercontact",
"email","position","company","zipcode",
"remark","imageid"},
"privacy=1",
null,
null,
null,
null);
...全文
2173 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
R0CK-Y0U 2012-05-30
  • 打赏
  • 举报
回复
有没有解释更清楚点的?比如排序都有哪些参数可以选择?
OlymHuang 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dr8737010 的回复:]

Java code
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

Since: API Level 1
Query the gi……
[/Quote]
幸好现在翻译工具强大 - -
太感谢了!
BadPattern 2012-02-28
  • 打赏
  • 举报
回复
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

Since: API Level 1
Query the given table, returning a Cursor over the result set.
Parameters

table The table name to compile the query against.
columns A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
groupBy A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
having A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
orderBy How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
Returns

A Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.

BadPattern 2012-02-28
  • 打赏
  • 举报
回复
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
查看query方法,形参名称很好的说明了它们的含义:
query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)

如果你在selection中不写"privacy=1",而是"privacy=?"那么selectionArgs就是"?"应该填写的内容
OlymHuang 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dr8737010 的回复:]

DB_TABLENAME ---- 数据库表名
String数组 ---- 表中数据字段名
privacy=1 ---- 查询where语句
[/Quote]
非常感谢,那么下面的哪些null呢?我是看的例子上这么写,上面没解释这个。
BadPattern 2012-02-28
  • 打赏
  • 举报
回复
DB_TABLENAME ---- 数据库表名
String数组 ---- 表中数据字段名
privacy=1 ---- 查询where语句
OlymHuang 2012-02-28
  • 打赏
  • 举报
回复
求高手点解

80,360

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧