Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of rows in a database table with Flutter SQFlite

How do I get the row count of a database table in Flutter. I am using the SQFlite plugin.

I assume that it is similar to Android, but Android has DatabaseUtils.queryNumEntries(db, TABLE_NAME). Does SQFlite have something similar?

I am answering the question to the best of my knowledge below, but I would be glad for a better answer if there is one.

like image 409
Suragch Avatar asked Jan 08 '19 18:01

Suragch


1 Answers

You can use

int count = Sqflite.firstIntValue(await db.rawQuery('SELECT COUNT(*) FROM table_name'));

where db is an SQFlite Database.

Source: I found this here and in the source code.

like image 142
Suragch Avatar answered Oct 01 '22 21:10

Suragch