(Summary of practical development issues-SqLite) sqlite implements the function of returning a single row and a single column by executing SQL statements

Source: Internet
Author: User

During android development, we often save temporary data to the Sqlite database, and analyze and process the stored data at a certain point in time of the application.

In the actual development process, query statistics and other operations will appear, then we are familiar with the query method

CursorAndroid. database. sqlite. SQLiteDatabase. query (StringTable,String[] Columns,StringSelection,String[] SelectionArgs,StringGroupBy,StringHaving,StringOrderBy)

It cannot adapt to statistical analysis.

This reminds us of the ExecuteScalar interface in the development of other languages, which executes SQL statements and returns a row or column. The following is an example of implementing such a function in sqlite (mainly used

Cursor android. database. sqlite. SQLiteDatabase. rawQuery (String SQL, String [] selectionArgs)

Such an Interface

Instance:

 

public int GetSumScore()

{

int resultscore=0;

String sql=" select sum(Score) from tempAnswerGuess";



Cursor cursor=db.rawQuery(sql, null);

cursor.moveToFirst();

resultscore= Integer.parseInt(cursor.getString(0));



return resultscore;

}
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.