Android(java)学习笔记141:SQLiteDatabase的query方法参数分析

时间:2023-03-09 18:33:48
Android(java)学习笔记141:SQLiteDatabase的query方法参数分析

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

  其中各种参数意思如下(如果其中某个参数不设置,可以指定为null):

distinct:distinct true if you want each row to be unique, false otherwise.

    table:表名。相当于select语句from关键字后面的部分。如果是多表联合查询,可以用逗号将两个表名分开。

  columns:要查询出来的列名。相当于select语句select关键字后面的部分。

  selection:查询条件子句,相当于select语句where关键字后面的部分,在条件子句允许使用占位符“?”

  selectionArgs:对应于selection语句中占位符的值,值在数组中的位置与占位符在语句中的位置必须一致,否则就会有异常。

  groupBy:相当于select语句groupby关键字后面的部分

having:相当于select语句having关键字后面的部分

orderBy:相当于select语句orderby关键字后面的部分

limit:指定偏移量和获取的记录数,相当于select语句limit关键字后面的部分