Example usage for android.database DatabaseUtils longForQuery

List of usage examples for android.database DatabaseUtils longForQuery

Introduction

In this page you can find the example usage for android.database DatabaseUtils longForQuery.

Prototype

public static long longForQuery(SQLiteDatabase db, String query, String[] selectionArgs) 

Source Link

Document

Utility method to run the query on the db and return the value in the first column of the first row.

Usage

From source file:Main.java

public static int getRowCount(SQLiteDatabase db, boolean distinct, String table, String[] columns,
        String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) {
    if (columns != null && columns.length > 0) {
        columns = new String[] { columns[0] };
    }/*from   ww w . java 2 s . co m*/
    String sql = SQLiteQueryBuilder.buildQueryString(distinct, table, columns, selection, groupBy, having,
            orderBy, limit);
    String countSelection = "SELECT count(*) FROM (" + sql + ")";
    return (int) DatabaseUtils.longForQuery(db, countSelection, selectionArgs);
}