Comparison of Android Rawquery and query

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 two queries and rawquery query statements, the main difference is that Rawquery is directly using the SQL statement query, that is, the first parameter string, within the string "?" "will be replaced by an array of subsequent string[], and the query function is an Android-encapsulated querying API: Its API documentation is as follows:
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 compared to the former, there is a benefit, the former rawquery you write SQL statements, it is possible to write a wrong or write a missing word spelling error when he will make a mistake, and the second is relatively small probability of error

Comparison of Android Rawquery and query

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.