Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count number of records in sqlite in Android

Tags:

android

sqlite

I am working on android project. I used sqlite database for it. I have tables in database. I have created databasehelper class. i want to count number of records in particular table. how can i achieve this ? any help will be appreciated?

like image 732
user1602798 Avatar asked Sep 15 '12 10:09

user1602798


People also ask

How do I count data in SQLite?

In SQLite the Count(*) function will return total number of rows available in a table, including the rows which contain NULL values. The Count(*) will not take any parameters other than the asterisk symbol (*). Now we will see how to use SQLite count(*) on emp_master to get total number of records in table.

How many records can SQLite hold?

The largest possible setting for SQLITE_MAX_PAGE_COUNT is 4294967294. When used with the maximum page size of 65536, this gives a maximum SQLite database size of about 281 terabytes. The max_page_count PRAGMA can be used to raise or lower this limit at run-time.

How many writes per second SQLite?

Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational speed of your disk drive.

Does iOS use SQLite?

Apple uses SQLite in many (most?) of the native applications running on Mac OS-X desktops and servers and on iOS devices such as iPhones and iPods. SQLite is also used in iTunes, even on non-Apple hardware.


1 Answers

This would be more efficient:

int numRows = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM table_name", null);

Or:

int numRows = DatabaseUtils.queryNumEntries(db, "table_name");
like image 192
Nick Bradbury Avatar answered Oct 03 '22 09:10

Nick Bradbury