public static long longForQuery(SQLiteDatabase db,String query,String[] selectionArgs){
  SQLiteStatement prog=db.compileStatement(query);
  try {
    return longForQuery(prog,selectionArgs);
  }
  finally {
    prog.close();
  }
}

public static long longForQuery ( SQLiteDatabase db , String query , String [ ] selectionArgs ) { SQLiteStatement prog = db . compileStatement ( query ) ; try { return longForQuery ( prog , selectionArgs ) ; } finally { prog . close ( ) ; } }
utility method to run the query on the db and return the value in the first column of the first row .
