当前位置:Gxlcms > 数据库问题 > SQLiteDatabase中query、insert、update、delete方法参数说明

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

("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);

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

标签:

人气教程排行