Sqlitedatabase query, INSERT, UPDATE, delete method parameter description

Source: Internet
Author: User

1. Sqlitedatabase object's query () interface:Public CursorQuery(string table, string[] columns, string selection, string[] Selectionargs,string groupBy, string having,string orderby,string limit)

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

Parameters
Table The table name to compile the query against. ( the name of the table to query. ) )
Columns A list of which columns to return. Passing NULL would return all columns, which are discouraged to prevent reading data from storage This isn ' t going to being use D. ( the column you want to display, if blank, returns all columns, not recommended to NULL if all columns are not returned )
Selection A filter declaring which rows to return, formatted as a SQL WHERE clause (excluding the where itself). Passing NULL would return all rows for the given table. (WHERE clause that declares the requirements of the row to be returned, and returns all rows of the table if it is empty.) )
Selectionargs May include? s in selection, which'll be replaced by the values from Selectionargs, in order that they appear in the Selection. The values would be bound as Strings. ( the condition value corresponding to the WHERE clause )
GroupBy A Filter declaring how to group rows, formatted as a SQL GROUP BY clause (excluding the group by itself). Passing null would cause the rows to is grouped. ( grouping, if empty, is not grouped. ) )
Having A filter declare which row groups to include in the cursor, if row grouping are being used, formatted as an SQL have Clau SE (excluding the having itself). Passing null would cause all row groups to be included, and was required when row grouping was not being used. (having the condition, if empty then return all (not recommended))
By How to order the rows, formatted as a SQL ORDER BY clause (excluding the order by itself). Passing NULL would use the default sort order, which could be unordered. ( sort by, empty is the default sort method )
Limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause. ( limit the number of records that are returned, not limited by the empty one )
Returns
    • A Cursor object, which is positioned before the first entry. Note Cursor that S is not a 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()接口:Public LongInsert(string table, String nullcolumnhack, contentvalues values)

Convenience method for inserting a row into the database.

Parameters
Table The table to insert the row into ( the name of the tables to insert the data )
Nullcolumnhack Optional May null . SQL doesn ' t allow inserting a completely empty row without naming at least one column name. If your provided values is empty, the No column names is known and a empty row can ' t be inserted. If not set to NULL, the nullColumnHack parameter provides the name of nullable column name to explicitly inserts a null into in the Case where your is values empty. ( when the values parameter is empty or there is no content in it, we will fail the insert (the underlying database does not allow a blank line to be inserted), in order to prevent this, we will specify a column name here, if we find the behavior to be inserted empty row, The value of the column name that you specify is set to null and then inserted into the database. )
Values This map contains the initial column values for the row. The keys should be the column names and the values of the column values ( a Contentvalues object, similar to a map. Stores the value in the form of a key-value pair. )
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); 3. The update () interface of the Sqlitedatabase object:public intUpdate (string table, contentvalues values, String whereclause, string[] whereargs)

Convenience method for updating rows in the database.

Parameters
Table The table to update in (the name to be updated)
Values A map from column names to new column values. Null is a valid value, that would be, translated to NULL. ( A Contentvalues object, similar to a map.) stores the value in the form of a key-value pair. )
Whereclause


Whereargs
The optional WHERE clause to apply when updating. Passing NULL would update all rows. ( optional WHERE statement )

The group of Args to deal with (expression in whereclause statement?) Placeholder parameter list )
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. Delete () interface of Sqlitedatabase object:public intDelete (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 would delete all rows. ( Optional WHERE statement )
The optional WHERE clause to apply when updating. Passing NULL would update all rows. (the expression in the Whereclause statement?) Placeholder parameter list )
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);This article was reproduced from: http://www.cnblogs.com/maxinliang/archive/2013/01/22/2871474.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.