============ 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