android rawquery和query对照

Cursor cursor = db.rawQuery("select name from *** where id=?

", new String[]{"1"});

Cursor cursor = db.query("***", new String[]{"name"}, "id=?", new String[]{"1"}, null, null, null);

上面是两个各自是query和rawQuery的查询语句,主要差别是rawQuery是直接使用SQL语句进行查询的。也就是第一个參数字符串,在字符串内的“?”会被后面的String[]数组逐一对换掉。而query函数是Android自己封装的查询API:它的API文档例如以下:

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

Query the given table, returning a Cursor over the result set.

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.

Returns

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

而后者query对照前者来讲就有一个优点。前者rawQuery你在写入SQL语句的时候,有可能写错了或者写漏了什什么拼错的单词时,他将是错误的,而相对来说,后者的错误的机率是相当小

版权声明:本文博客原创文章。博客,未经同意,不得转载。

时间: 2024-08-18 08:28:30

android rawquery和query对照的相关文章

android rawquery和query的比较

Cursor cursor = db.rawQuery("select name from *** where id=?", new String[]{"1"}); Cursor cursor = db.query("***", new String[]{"name"}, "id=?", new String[]{"1"}, null, null, null); 上面是两个分别是quer

Android Permission中英对照 【转】

android.permission.ACCESS_CHECKIN_PROPERTIES Allows read/write access to the "properties" table in the checkin database, to change values that get uploaded 允许读写访问 "properties"表在checkin数据库中,改值可以修改上传 android.permission.ACCESS_COARSE_LOCA

Android面试经验1

1,java基本数据类型. Byte.short.int.long.float.double.char.boolean. 1         2       2     2      4        8           2       根据机器来定 2,java访问控制符含义. 类内部      本包      子类       外部包 public        是           是         是          是 protect      是          是  

android 数据库的增删改查

主java package com.itheima.crud; import android.app.Activity; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import com.ithei

Android SQLite 的介绍和使用(二)

上一节简单介绍了一下SQLite,这一节我们开始SQLite在Android中的应用. Android提供了一个数据库的帮助类 SQLiteOpenHelper,用于管理数据库的创建和版本管理.我们可以继承这个类,实现它的 onCreate和 onUpgrade方法.我们可以在这里设置数据库的版本,数据库名称,创建数据库表等.下面看代码: public class DBHelper extends SQLiteOpenHelper { //数据库的版本号必须要大于1 public final s

Android数据的四种存储方式

很清晰的思路,转自Android数据的四种存储方式 作为一个完成的应用程序,数据存储操作是必不可少的.因此,Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放于“data/data/程序包名”目录下,所以要实现数据共享,正确方式是使用Content Provider. SQLite: SQLite是一个轻量级的数据库,支持基本SQL语法,是常被采用

Android SQLite总结[转载]

[转载] :http://blog.163.com/zqy216_2008/blog/static/4119371820119954812509/ 最近在做的项目涉及到了SQLite,大学时没有好好学习数据库,趁这次项目学习总结下. SQLite是一款轻量级数据库,它的设计目的是嵌入式,而且它占用的资源非常少,在嵌入式设备中,可能只需要几百KB,这也是 Android 系统采用 SQLite 数据库的原因之一. 下面给出SQLite的数据类型. 一般数据采用的固定的静态数据类型,而SQLite采

android菜鸟学习笔记20----Android数据存储(四))Android数据库操作

Android内置了一个名为SQLite的关系型数据库,这是一款轻量型的数据库,操作十分简便.SQLite与别的数据库不同的是,它没有数据类型.可以保存任何类型的数据到你所想要保存的任何表的任何列中.但它又支持常见的类型比如: NULL, VARCHAR, TEXT, INTEGER, BLOB, CLOB...等. 唯一的例外是:integer primary key 此字段只能存储64位整数. 在JAVA项目中,要使用JDBC操作数据库需要加载数据库驱动,连接数据库等操作.Android简化

Android数据存储 如何搞定SQLite Database

转载请注明出处:明桑Android 在Android平台下有各种不同方法可以实现应用程序数据的存储和管理(SharedPerferences,File,SQLiteDatabase,网络存储),方法的选择依赖于需要存储的数据类型和数据结构.SQLite数据库能够安全而有效地解决结构化数据的存储问题: 这里主要介绍SQLite相关的用法,以及对数据库常见操作的封装. 最后,作为一个综合案例,做一个简单的学生管理的demo,创建student.db,包括name,grade字段,实现增.删.改.查的