Issues with SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database

============ Problem Description ============


I created an empty table with no data added, and the return value is 1 with the following method
String sql = "SELECT COUNT (*) from" + Tablename;return sqlitedatabase.rawquery (sql, NULL). GetCount ();

But using the following method is 0, do not know why, have the great god know?
Return sqlitedatabase.query (TABLENAME, NULL, NULL, NULL, NULL, NULL, NULL). GetCount ();

============ Solution 1============


Your first code is select COUNT (*), so no data will return a 0 in time, right? So after the select, there is a return value, the second is because the database is empty, so the number is 0

Now that you've used select COUNT (*), there's no need to use GetCount (), and from GetCount () you can't get the value of your select.

============ Solution 2============


To Harryweasley

Your code does not have the same SQL statement as the query construct, and the cursor that gets the result is not the same rawquery.
The SQL statement for Rawquery is select COUNT (*) from, and the cursor result is a record, which is 0,getcount () =1
The SQL statement for query is select * From,cursor no record, GetCount () =0

Cursor.getcount ()

Return the number of rows in database table.

The difference between http://www.ijy6.com/questions/5441125979763/sqlitedatabase-query-and-rawquery-

Issues with SQLite database

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.