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

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 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
  • Cursor object,
    which is positioned before the first entry. Note that Cursors
    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 (String table, String nullColumnHack, ContentValues 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 (String table, ContentValues values, String whereClause, String[] 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 (String table, String whereClause, String[] 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);

时间: 2024-09-30 18:14:15

SQLiteDatabase中query、insert、update、delete方法参数说明的相关文章

在PHPLIB中的MYSQL类中加INSERT,UPDATE,DELETE等函数

<?php/* * Session Management for PHP3 * * Copyright (c) 1998-2000 NetUSE AG *                    Boris Erdmann, Kristian Koehntopp * * $Id: db_mysql.inc,v 1.2 2000/07/12 18:22:34 kk Exp $ * */ class DB_Sql {    /* public: connection parameters */  va

SQLServer 2008中SQL增强之三 Merge(在一条语句中使用Insert,Update,Delete)_mssql2008

SQL Server 2008提供了一个增强的SQL命令Merge,用法参看MSDN:http://msdn.microsoft.com/zh-cn/library/bb510625.aspx 功能:根据与源表联接的结果,对目标表执行插入.更新或删除操作.例如,根据在另一个表中找到的差异在一个表中插入.更新或删除行,可以对两个表进行同步. 我们看一个例子,假如,有一总产品列表,一个分店产品列表,需要从分店添加产品时更新总产品列表. 总产品表,分店产品表结构完全一致: 复制代码 代码如下: if

Merge(在一条语句中使用Insert,Update,Delete) 对两个表进行同步数据

SQL Server 2008提供了一个增强的SQL命令Merge,用法参看MSDN:http://msdn.microsoft.com/zh-cn/library/bb510625.aspx 功能:根据与源表联接的结果,对目标表执行插入.更新或删除操作.例如,根据在另一个表中找到的差异在一个表中插入.更新或删除行,可以对两个表进行同步. 我们看一个例子,假如,有一总产品列表,一个分店产品列表,需要从分店添加产品时更新总产品列表. 总产品表,分店产品表结构完全一致: if OBJECT_ID('

LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作

我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作 .这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作插入(Insert)1.简单形式 说明:new一个 对象,使用InsertOnSubmit方法将其加入到对应的集合中,使用SubmitChanges ()提交到数据库. NorthwindDataContext db = new NorthwindDataContext(); var newCustome

asp access insert update delete 使用

本教程是一篇asp入门篇的初级教程了,主要是讲asp access insert update delete 简单的使用哦,好了下面我们把它们写在一个函数里面然后再举例说明. Function add_del_update(tablename,str,id) Select Case str  Case "insert":    sql="select * from ["&tablename&"] where id=null"   

SQL Server触发器insert update delete示例

·只有inserted表有数据时,当前操作为insert: ·inserted和deleted两张表都有数据时,当前操作为update: ·只有deleted表有数据时,当前操作为delete. 创建触发器用 CREATE TRIGGER  代码如下 复制代码 CREATE TRIGGER 触发器名称 ON 表名 FOR INSERT.UPDATE 或 DELETE AS nserted.deleted 这是两个虚拟表,inserted 保存的是 insert 或 update 之后所影响的记录

简述SQL SERVER触发器内INSERT,UPDATE,DELETE的三种状态

一个触发器内三种INSERT,UPDATE,DELETE状态 CREATE   TRIGGER   tr_T_A   ON     T_A   for   INSERT,UPDATE,DELETE        如IF   exists   (select   *   from   inserted)   and   not   exists   (select   *   from   deleted)   则为   INSERT  如IF   exists(select   *   from

MySQL 4.1.0 中文参考手册 --- 6.4 数据操纵:SELECT, INSERT, UPDATE, DELETE

mysql|select|参考|参考手册|数据|中文 MySQL 4.1.0 中文参考手册 --- 犬犬(心帆)翻译 MySQL Reference Manual for version 4.1.0-alpha. 6.4 数据操纵:SELECT, INSERT, UPDATE, DELETE6.4.1 SELECT 句法 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACH

c# 配置 objectDatasource时 没有 update delete方法

问题描述 c#配置objectDatasource时没有updatedelete方法.点配置update下面的"选择方法"为空.delete那里也为空.但是select和insert那里有方法可以选择为什么.? 解决方案 解决方案二:你后台没写那些方法吧解决方案三:忘记说了..我是连的强类型dataset解决方案四:强类型的dataset,有必要使用objectDatasource吗??解决方案五:强类型的dataset没有对应的dataadapter吗?解决方案六:我也是遇到了这样的