query()的参数讲解

SQLiteDatabase包含有四个参数不同的query函数,分别包含有7,8,9,10个参数。这么多的参数很难记,所以在这里以10个参数的query函数为例,梳理一下各个参数的意义。

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

1 distinct,boolean: true if you want each row to be unique, false otherwise.(设置为true,每一行的数据必须唯一。反之亦然。)
2. table,String: The table name to compile the query against.(query函数要操作的表名。)
3. columns,String[]: 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.(要返回的列的名字的数组。如果设置为null,返回所有列,如果不需要使用所有列,不建议这么做。)
4. selection,String: 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.(一个决定返回哪一行的过滤器,相当于SQL语句中的 WHERE 关键字。传递null则会返回给定表的所有行。)
5. selectionArgs,String: 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.(用于替换上一个参数中的 ? ,顺序对应selection中?的顺序。格式限制为String格式。)
6. groupBy,String: 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.(用于设定返回行的分组方式,相当于SQL语句中的GROUP BY 关键字。传递null表示返回的行不会被分组。)
7. having,String: 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.(决定哪一行被放到Cursor中的过滤器。如果使用了行分组,相当于SQL语句中的HAVING关键字。传递null会导致所有的行都包含在内,前提是groupBy属性也设置为null。)
8. orderBy,String: 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.(行的排列方式,相当于SQL语句中的“ORDER BY”关键字,传递null表示使用默认的排序方式,可能是无序排列。)
9. limit,String: Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.(设置query语句返回行的数量,相当于SQL语句中的“LIMIT”关键字,传递null表示没有设置limit语句。注意格式为String,传递的时候需要传递数字字符串,例如“12”)
10. cancellationSignal,CancellationSignal: A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown when the query is executed.(取消程序操作的信号,如果没有则设置为null。如果操作取消了,query语句运行时会抛出OperationCanceledException异常。)

含有7个参数的query函数不包含1,9,10,也就是distinct,limit,cancellationSignal。
含有8个参数的query函数不包含1,10,也就是distinct,cancellationSignal。
含有9个参数的query函数不包含10,也就是cancellationSignal。

使用rawQuery()

当然如果想使用原生的SQL语句,可以用rawQuery()
Cursor rawQuery (String sql, String[] selectionArgs)
或者
Cursor rawQuery (String sql, String[] selectionArgs, CancellationSignal cancellationSignal)

里面的参数和query()中的参数是一致的。

Android SQLiteDatabase.query()各个参数的意义相关推荐

  1. android dbinfo函数,android SQLiteDatabase中的update函数用法?

    创建数据库 Android 不自动提供数据库.在 Android 应用程序中使用 SQLite,必须自己创建数据库,然后创建表.索引,填充数据.Android 提供了 SQLiteOpenHelper ...

  2. android中接口的作用是什么意思,详解Android接口Interface的使用和意义

    本文介绍是Android的一个重要的东西,接口Interface,详解两个方面: (1)Java是继承的,接口Interface是可以多个的,恰恰弥补了这个缺点. (2)回调,接口Interface里 ...

  3. 在linux kernel或android中解析cmdline参数

    文章目录 ★★★ 友情链接 : 个人博客导读首页-点击此处 ★★★ Kernel command line: earlycon androidboot.selinux=permissive uart_ ...

  4. android settext 参数,Android TextView.setTextColor()的参数设置方式

    摘要:Android TextView.setTextColor()的参数设置方式 查了下资料发现setTextColor()的参数应该写成以下的这种形式: setTextColor(0xFF0000 ...

  5. Listen第二个参数的意义

    Listen第二个参数的意义 文章转载于:http://blog.csdn.net/weiyuefei/article/details/52239315 今天主要回顾下listen的第二个参数的意义. ...

  6. Android 系统(260)---Android 读取SIM卡参数

    Android 读取SIM卡参数 package com.water.activity; import java.util.List; import android.app.Activity; imp ...

  7. ReactNative入门之android与rn初始化参数的传递

    1.基本理念 RN APP本质上也是原生APP,只是在原生APP中加入了React Native视图的支持. 因此获取RN APP的启动参数的方法原生APP是一样的,获取启动参数后再通过合适的方法传递 ...

  8. android rn动态技术,ReactNative入门之android与rn初始化参数的传递

    1.基本理念 RN APP本质上也是原生APP,只是在原生APP中加入了React Native视图的支持. 因此获取RN APP的启动参数的方法原生APP是一样的,获取启动参数后再通过合适的方法传递 ...

  9. sklearn模型中random_state参数的意义

    sklearn模型中random_state参数的意义 random_state 意义 使用情况 random_state 意义 例如:在sklearn可以随机分割训练集和测试集(交叉验证),只需要在 ...

  10. GPDB中gp_vmem_protect_limit参数的意义

    gp_vmem_protect_limit参数的意义 1.gp_vmem_protect_limit参数说明 1)在启用了基于资源队列的资源管理系统时,gp_vmem_protect_limit参数表 ...

最新文章

  1. Spring《五》集合的注入方式
  2. python 导入numpy 导致多进程绑定同一个CPU问题解决方法
  3. webpack之font-awesome
  4. 直播丨数据安全:Oracle多场景下比特币勒索的揭密与恢复实战
  5. 如何自动填充网页表单_流量型称重型充绒机充棉机如何选择,教你轻松辨别全自动填充机器...
  6. 快速配置vs2012+opencv
  7. springMVC+hibernate + layui分页
  8. 【FIRST USE】第一次用git把代码上传到github
  9. python趣味编程_戏说《西游记》之Python趣味编程:第四回 拜师学艺 破盘中之谜...
  10. 数论入门 2021-2-28
  11. 开机后台占用严重?教你如何清理常见后台占用
  12. 我的架构感悟:从美国宪法学习架构设计原则
  13. Spring —— Spring 手册官网下载地址
  14. 计算机二级选择题瞎蒙,一级消防员考试,一级消防员考试题大全
  15. 为什么每次开机都要进行磁盘检查?
  16. 计算机游戏软件使用说明书,虚贝游戏上号器怎么用 使用方法详解
  17. 牛客网C语言 算学分绩
  18. AccessViolationException
  19. 徐州当铺模型,乡村金融中心的建立
  20. 给定一个含n(n≥1)个整数的数组,请设计一个在时间上尽可能高效的算法,找出数组中未出现的最小正整数。

热门文章

  1. 记一次线上Zabbix对Redis监控实录
  2. 51nod 1833 状压dp加一点图论
  3. 算法笔记_039:杨辉三角形(Java)
  4. Codeforces Round #110 (Div. 2)
  5. iOS 开发中常见的设计模式
  6. 使用 JavaScript File API 实现文件上传
  7. 图解FCKeditor在asp.net环境的安装(上)
  8. 信息抽取大一统:百度中科院发布通用抽取模型UIE,刷新13个IE数据集SOTA!
  9. 苏神吐槽 | 开局一段扯,数据全靠编?真被一篇“神论文”气到了
  10. 【比赛经验】ALL in BERT:一套操作冲进排行榜首页