Android Rawquery and query control

Source: Internet
Author: User

cursor cursor = db.rawquery ("SELECT name from * * * * where id=?

", New string[]{" 1 "});
cursor cursor = db.query ("* * *", new string[]{"name"}, "Id=?", New string[]{"1"}, NULL, NULL, NULL);

The above is the two queries and rawquery query statements, the main difference is that rawquery is directly using SQL statements to query. That is, the first parameter string, within the string "?" "will be replaced by an array of subsequent string[]. and the query function is the search API that Android itself encapsulates: its API documentation such as the following:
Public Cursor Query (string table, string[] columns, string selection, string[] Selectionargs, string groupBy, String Having, String-by-clause)

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

Table
The table name to compile the query against.

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.

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.

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.

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.

having
A Filter Declare which row groups to include in the cursor, if row grouping are being used, formatted as an SQL have clause (excluding the having itself). Passing null would cause all row groups to be included, and was required when row grouping was not being used.

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.


Returns
? A Cursor object, which is positioned before the first entry. Note that Cursors is not synchronized, see the documentation for more details.

The latter query has an advantage over the former. The former rawquery you write the SQL statement, it is possible to write a wrong or write out what misspelled words, he will be wrong, and relatively speaking, the probability of the latter's error is quite small

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android Rawquery and query control

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.