The query operation in SQLite

Source: Internet
Author: User

The query () method actually splits the SELECT statement into several components and then acts as an input parameter to the method:
Sqlitedatabase db = Databasehelper.getwritabledatabase ();
cursor cursor = db.query ("Person", new string[]{"Personid,name,age"}, "name like", New string[]{"% smart%"}, NULL, NULL, "PE Rsonid desc "," ";");

while (Cursor.movetonext ()) {
int PersonID = cursor.getint (0); Gets the value of the first column, starting with the 0 index of the first column
String name = cursor.getstring (1);//Gets the value of the second column
int age = Cursor.getint (2);//Gets the value of the third column
}
Cursor.close ();
Db.close ();
The above code is used to find the name field from the person table contains "wisdom" records, matching records sorted in descending order of PersonID, the results of the sorting is skipped the first record, only 2 records are obtained.
Query (table, columns, selection, Selectionargs, GroupBy, have, to-do, limit) methods The meaning of each parameter:
Table: List name. Corresponds to the part of the SELECT statement following the FROM keyword. If you are a multi-table union query, you can separate the two table names with a comma.
Columns: The name of the column to query. Corresponds to the part of the SELECT statement after the SELECT keyword.
Selection: The query condition clause, which corresponds to the section after the WHERE keyword of the SELECT statement, allows the placeholder "?" to be used in the conditional clause.
Selectionargs: Corresponds to the value of the placeholder in the selection statement, the position of the value in the array must match the position of the placeholder in the statement, or there will be an exception.
GroupBy: Equivalent to the part of the SELECT statement after the GROUP by keyword
Having: equivalent to the part of the SELECT statement after the HAVING keyword
ORDER BY: Equivalent to the part of the SELECT statement that follows a keyword, such as: PersonID DESC, age ASC;
Limit: Specifies the offset and number of records fetched, which is equivalent to the portion of the SELECT statement after the Limit keyword

The query operation in SQLite

Related Article

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.