Sqlitedatabase query, INSERT, UPDATE, delete method parameter description

Source: Internet
Author: User

Sqlitedatabase object's query () interface: 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 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);

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 (the name of the table to insert the data)
N Ullcolumnhack Optional; may be  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 Expli citly insert a NULL into in the case where your  values  is empty. (  When the values parameter is empty or there is no content in it, our insert will fail (the underlying database does not allow the insertion of a blank line), in order to prevent this, we will specify a column name here, then if we find that the behavior will 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);Update () interface for the Sqlitedatabase object: 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 (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)Delete () interface for sqlitedatabase object: 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 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);

Sqlitedatabase query, INSERT, UPDATE, delete method parameter description

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.