SQLiteDatabase中query、insert、update、delete方法参数说明

转载 2016年06月01日 11:00:25

原文地址:http://www.cnblogs.com/maxinliang/archive/2013/01/22/2871474.html

1、SQLiteDataBase对象的query()接口:
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs,
                               String groupBy, String having,String orderBy,String limit)

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

Parameters
table The table name to compile the query against.(要查询的表名.)
columns A list of which columns to return. Passing null will return allcolumns, which is discouraged to prevent reading data from storagethat isn't going to be used.(想要显示的列,若为空则返回所有列,不建议设置为空,如果不是返回所有列)
selection A filter declaring which rows to return, formatted as an SQL WHEREclause (excluding the WHERE itself). Passing null will return allrows for the given table.(where子句,声明要返回的行的要求,如果为空则返回表的所有行。)
selectionArgs You may include ?s in selection, which will be replaced by thevalues from selectionArgs, in order that they appear in theselection. The values will be bound as Strings.( where子句对应的条件值)
groupBy A filter declaring how to group rows, formatted as an SQL GROUP BYclause (excluding the GROUP BY itself). Passing null will cause therows to not be grouped.(分组方式,若为空则不分组.)
having A filter declare which row groups to include in the cursor, if rowgrouping is being used, formatted as an SQL HAVING clause(excluding the HAVING itself). Passing null will cause all rowgroups to be included, and is required when row grouping is notbeing used.(having条件,若为空则返回全部(不建议))
orderBy How to order the rows, formatted as an SQL ORDER BY clause(excluding the ORDER BY itself). Passing null will use the defaultsort order, which may be unordered.(排序方式,为空则为默认排序方式)
limit Limits the number of rows returned by the query, formatted as LIMITclause. Passing null denotes no LIMIT clause.(限制返回的记录的条数,为空则不限制)
Returns
  • Cursor object,which is positioned before the first entry. Notethat Cursorsare not synchronized, see the documentation for more details.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("a")};

query("user",new String[] { "username","password" },"username=?"args,null,null,null, null);


2、SQLiteDataBase对象的insert()接口:

publiclong insert (String table, String nullColumnHack, ContentValues values)

Convenience method forinserting a row into the database.

Parameters
table the table to insert the row into(要插入数据的表的名称)
nullColumnHack optional; may be null.SQL doesn't allow inserting a completely empty row without namingat least one column name. If yourprovided valuesisempty, no column names are known and an empty row can't beinserted. If not set to null, the nullColumnHack parameterprovides the name of nullable column name to explicitly insert aNULL into in the case where your values isempty.( 当values参数为空或者里面没有内容的时候,我们insert是会失败的(底层数据库不允许插入一个空行),为了防止这种情况,我们要在这里指定一个列名,到时候如果发现将要插入的行为空行时,就会将你指定的这个列名的值设为null,然后再向数据库中插入。)
values this map contains the initial column values for the row. The keysshould be the column names and the values the columnvalues(一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
Returns
  • the row ID of the newly insertedrow, or -1 if an error occurred
示例:
ContentValues cv = new ContentValues();
cv.put("username""a");
cv.put("password""b");
insert("user"null,cv);
 
 
3、SQLiteDataBase对象的update()接口:

publicint update (String table, ContentValues values, String whereClause, String[] whereArgs)

Convenience method for updatingrows in the database.

Parameters
table the table to update in(要更新的表名)
values a map from column names to new column values. null is a valid valuethat will be translated to NULL.(一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
whereClause


whereArgs
the optional WHERE clause to apply when updating. Passing null willupdate all rows.(可选的where语句)

the group of args to dealwith(whereClause语句中表达式的?占位参数列表
)
Returns
  • the number of rows affected
ContentValues cv = new ContentValues();
cv.put("username""c");
cv.put("password""d");
String[] args = {String.valueOf("a")};
update("user",cv, "username=?",args)
 
 
4、SQLiteDataBase对象的delete()接口:

publicint delete (String table, String whereClause, String[] whereArgs)

Convenience method for deletingrows in the database.

Parameters
table the table to delete from
whereClause

whereArgs
the optional WHERE clause to apply when deleting. Passing null willdelete all rows.(可选的where语句)
the optional WHERE clauseto apply when updating. Passing null will update allrows.(whereClause语句中表达式的?占位参数列表)
Returns
  • the number of rows affected if awhereClause is passed in, 0 otherwise. To remove all rows and get acount pass "1" as the whereClause.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("c")};
delete("user""username=?",args);

SQLiteDataBase中query、insert、update、delete方法参数说明

SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selecti...
  • wuyezhu
  • wuyezhu
  • 2014年08月24日 09:14
  • 234

【Content Provider】SQLiteDatabase中query、insert、update、delete方法参数说明

http://blog.sina.com.cn/s/blog_69092aea0101879o.html SQLiteDataBase对象的query()接口: public ...
  • horsttnann
  • horsttnann
  • 2014年04月08日 13:50
  • 347

(MyStudy:二)SQLiteDatabase中query、insert、update、delete方法参数说明

最近在想学习下Sqlite数据库的操作,但是网上找到好久都没找到,一般信息不明细,想要用的时候都不知道怎么传参数,后来还是找到了比较符合的API接口注释,就记下来: 1、SQLiteDataBase...
  • wyb1078437881
  • wyb1078437881
  • 2016年07月13日 15:24
  • 151

《Android学习笔记》SQLiteDatabase中query、insert、update、delete方法参数说明

1、SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selecti...
  • HecLzo
  • HecLzo
  • 2017年11月27日 18:52
  • 151

SQLiteDatabase中query、insert、update、delete方法参数说明

SQLiteDatabase中query、insert、update、delete方法参数说明 SQLiteDataBase对象的query()接口:   public Cursor query(S...
  • jianghujiujiyihao
  • jianghujiujiyihao
  • 2013年11月27日 00:42
  • 552

Android学习笔记九:SQLiteDatabase中query、insert、update、delete方法参数说明

1、SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection...
  • wuhenyouyuyouyu
  • wuhenyouyuyouyu
  • 2016年05月14日 15:10
  • 5054

SQLiteDatabase 自带添加、删除、更新、查询的操作方

Android学习笔记----SQLiteDatabase 自带添加、删除、更新、查询的操作方法:实现添加,删除,更新, 7.除了前面给大家介绍的execSQL()和rawQuery()方法...
  • qingfeng45697
  • qingfeng45697
  • 2016年10月08日 14:53
  • 2640

SQLiteDatabase类的query(),insert(),update(),delete()方法参数说明

1、SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection...
  • u010335298
  • u010335298
  • 2016年08月03日 16:27
  • 374

SQLiteDatabase.insert函数参数解释说明

public long insert (String table, String nullColumnHack, ContentValues values) Added in API level...
  • luofeixiongsix
  • luofeixiongsix
  • 2015年09月29日 13:19
  • 1851

SQLiteDatabase query语句参数详解

问:SQLiteDatabase dbInstance; Cursor cursor = dbInstance.query(String table,String []Columns, String...
  • Mahuicool
  • Mahuicool
  • 2016年11月17日 13:44
  • 459
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SQLiteDatabase中query、insert、update、delete方法参数说明
举报原因:
原因补充:

(最多只允许输入30个字)