Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the row count of a query in Android using SQLite?

How do I get the row count of a query in Android using SQLite? It seems my following method does not work.

public int getFragmentCountByMixId(int mixId) {     int count = 0;     SQLiteDatabase db = dbOpenHelper.getWritableDatabase();      Cursor cursor = db.rawQuery(         "select count(*) from downloadedFragement where mixId=?",         new String[]{String.valueOf(mixId)});     while(cursor.moveToFirst()){         count = cursor.getInt(0);     }     return count; }     
like image 713
David Avatar asked Jun 15 '11 00:06

David


People also ask

How do I count rows in SQLite?

SQLite COUNT() function illustration As you can see clearly from the output, the result set includes NULL and duplicate rows. In this example, the COUNT(c) returns the number of non-null values. It counts the duplicate rows as separate rows.

How do you get total row count?

Just click the column header. The status bar, in the lower-right corner of your Excel window, will tell you the row count. Do the same thing to count columns, but this time click the row selector at the left end of the row. If you select an entire row or column, Excel counts just the cells that contain data.

How many rows of data can SQLite handle?

The max_page_count PRAGMA can be used to raise or lower this limit at run-time. The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19). This limit is unreachable since the maximum database size of 281 terabytes will be reached first.


1 Answers

Cursor.getCount()

like image 107
michaelg Avatar answered Sep 28 '22 17:09

michaelg