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