diff options
author | Hyoseong Kim <muzbit.kim@lge.com> | 2013-03-04 20:02:47 +0900 |
---|---|---|
committer | git-lg-database.lge.com <lg-database@lge.com> | 2013-04-01 15:55:55 +0900 |
commit | ac4daee248b4bb0cb658c83437e4a9d93c6dce2d (patch) | |
tree | 05150367de93552334d06c05e313150ebdba6ccc /core/java/android/database | |
parent | f5276c16ad97d94f8773938012ae54f8c7ba450a (diff) | |
download | frameworks_base-ac4daee248b4bb0cb658c83437e4a9d93c6dce2d.zip frameworks_base-ac4daee248b4bb0cb658c83437e4a9d93c6dce2d.tar.gz frameworks_base-ac4daee248b4bb0cb658c83437e4a9d93c6dce2d.tar.bz2 |
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
Diffstat (limited to 'core/java/android/database')
-rw-r--r-- | core/java/android/database/DatabaseUtils.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/core/java/android/database/DatabaseUtils.java b/core/java/android/database/DatabaseUtils.java index 1fc1226..e2d9724 100644 --- a/core/java/android/database/DatabaseUtils.java +++ b/core/java/android/database/DatabaseUtils.java @@ -792,6 +792,18 @@ public class DatabaseUtils { } /** + * 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. */ |