先介绍一下几个方法:
1:删除
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 | the optional WHERE clause to apply when deleting. Passing null will delete all rows. |
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.
2, 插入
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 | SQL doesn't allow inserting a completely empty row, so if initialValues is empty this column will explicitly be assigned a NULL value |
values | this map contains the initial column values for the row. The keys should be the column names and the values the column values |
Returns
- the row ID of the newly inserted row, or -1 if an error occurred
public long replace (String table,String nullColumnHack, ContentValues initialValues)
Convenience method for replacing a row in the database.
Parameters
table | the table in which to replace the row |
---|---|
nullColumnHack | SQL doesn't allow inserting a completely empty row, so if initialValues is empty this row will explicitly be assigned a NULL value |
initialValues | this map contains the initial column values for the row. The key |
Returns
- the row ID of the newly inserted row, or -1 if an error occurred
4 更新
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. |
whereClause | the optional WHERE clause to apply when updating. Passing null will update all rows. |
Returns
- the number of rows affected
5 查询
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 da |
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. |
limit | Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause. |
Returns
- A Cursor object, which is positioned before the first entry
See Also
privatestaticfinal StringDATABASE_CREATE