Add additional Method that check whether a table is empty or not
Application Devleopers are using queryNumEntries API implemented by "COUNT(*)" to check whether a table is empty or not. COUNT(*) has to process the entire table to compute the result. But, "EXISTS" can stop after a single matching row has been found. So, Using "EXISTS" is more faster than "COUNT(*)" I added new API using "EXISTS" to check whether a table is empty or not Change-Id: Idcc2633d0a5349c59f41e125cf34c9dc6622cdbe
This commit is contained in:
committed by
git-lg-database.lge.com
parent
f5276c16ad
commit
ac4daee248
@@ -791,6 +791,18 @@ public class DatabaseUtils {
|
||||
selectionArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the table to check whether a table is empty or not
|
||||
* @param db the database the table is in
|
||||
* @param table the name of the table to query
|
||||
* @return True if the table is empty
|
||||
* @hide
|
||||
*/
|
||||
public static boolean queryIsEmpty(SQLiteDatabase db, String table) {
|
||||
long isEmpty = longForQuery(db, "select exists(select 1 from " + table + ")", null);
|
||||
return isEmpty == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to run the query on the db and return the value in the
|
||||
* first column of the first row.
|
||||
|
||||
Reference in New Issue
Block a user