博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQLiteDatabase中query、insert、update、delete方法参数说明
阅读量:5892 次
发布时间:2019-06-19

本文共 4561 字,大约阅读时间需要 15 分钟。

原文:http://blog.sina.com.cn/s/blog_69092aea0101879o.html
 
SQLiteDataBase对象的query()接口:

 

public   query (  table,   columns,   selection,   selectionArgs,   groupBy,   having,   orderBy,  limit)

Query the given table, returning a  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.(where子句,声明要返回的行的要求,如果为空则返回表的所有行。)
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.( where子句对应的条件值)
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.(having条件,若为空则返回全部(不建议))
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
  •  object, which is positioned before the first entry. Note that s are 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);

 

SQLiteDataBase对象的insert()接口:

public long insert ( table,  nullColumnHack,  values)

Convenience method for inserting 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 naming at least one column name. If your provided valuesis empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty.( 当values参数为空或者里面没有内容的时候,我们insert是会失败的(底层数据库不允许插入一个空行),为了防止这种情况,我们要在这里指定一个 列名,到时候如果发现将要插入的行为空行时,就会将你指定的这个列名的值设为null,然后再向数据库中插入。)
values this map contains the initial column values for the row. The keys should be the column names and the values the column values(一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
Returns
  • the row ID of the newly inserted row, or -1 if an error occurred
示例:
ContentValues cv = new ContentValues();
cv.put(
"username"
"a");
cv.put(
"password"
"b");
insert("user", 
null
, cv);
 
 
SQLiteDataBase对象的update()接口:

public int update ( table,  values,  whereClause,  whereArgs)

Convenience method for updating rows in the database.

Parameters
table the table to update in(要更新的表名)
values a map from column names to new column values. null is a valid value that will be translated to NULL.(一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
whereClause
whereArgs
the optional WHERE clause to apply when updating. Passing null will update all rows.(可选的where语句)
the group of args to deal with(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)
 
 
SQLiteDataBase对象的delete()接口:

public int delete ( table,  whereClause,  whereArgs)

Convenience method for deleting rows in the database.

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

转载于:https://www.cnblogs.com/mochaMM/p/5112929.html

你可能感兴趣的文章
C++它 typedef void *HANDLE
查看>>
Git常用命令
查看>>
Linux下查看MySQL的安装路径
查看>>
C#获取磁盘列表与信息
查看>>
mysql学习笔记4---mysql 复制---源代码
查看>>
Linux设备驱动之semaphore机制【转】
查看>>
每天一个linux命令(25):linux文件属性详解
查看>>
【android】getDimension()、getDimensionPixelOffset()和getDimensionPixelSize()区别详解
查看>>
HDU 3280 Equal Sum Partitions(二分查找)
查看>>
第一个之出现一次的字符
查看>>
go微服务框架go-micro深度学习(三) Registry服务的注册和发现
查看>>
expectFAQ(附一个python批量任务脚本)--持续更新
查看>>
HDU 2492 Ping pong
查看>>
JPA的Embeddable注解
查看>>
Maven在Eclipse中的实用小技巧
查看>>
步步为营Hibernate全攻略(一)构建Hibernate框架环境
查看>>
【开放源代码】【谐波数据生成器】【上位机软件】(版本:0.00)
查看>>
Hibernate基础-HelloWord
查看>>
Android Studio系列教程四--Gradle基础
查看>>
添加cordova-plugin-file-opener2后,打包出错
查看>>