Example usage for android.database Cursor getCount

List of usage examples for android.database Cursor getCount

Introduction

In this page you can find the example usage for android.database Cursor getCount.

Prototype

int getCount();

Source Link

Document

Returns the numbers of rows in the cursor.

Usage

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getFavoriteAuthors(Context context) {

    HashSet<String> favoriteAuthors = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor c = dbread.rawQuery("SELECT name FROM favorite_users", null);
    if (c.getCount() > 0) {
        favoriteAuthors = new HashSet<String>(c.getCount());
        c.moveToFirst();//from w  ww  . jav  a 2  s . c o  m

        int count = c.getCount();
        for (int i = 0; i < count; i++) {
            favoriteAuthors.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (favoriteAuthors == null)
        favoriteAuthors = new HashSet<String>(0);
    return favoriteAuthors;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static String[] getSubscribedGroups(Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor cur = dbread.rawQuery("SELECT name FROM subscribed_groups", null);
    int c = cur.getCount();
    String[] subscribed = null;//from  w ww  . j av a2  s.  co  m
    if (c > 0) {
        subscribed = new String[c];

        cur.moveToFirst();
        for (int i = 0; i < c; i++) {
            subscribed[i] = cur.getString(0);
            cur.moveToNext();
        }
    }

    cur.close();
    dbread.close();
    db.close();
    return subscribed;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static Vector<Long> getPendingOutgoingMessageIds(Context context) {

    Vector<Long> retVal = null;
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor c = dbread.rawQuery("SELECT _id FROM offline_sent_posts", null);
    int count = c.getCount();

    if (count == 0) {
        retVal = new Vector<Long>(0);
    } else {//w  w  w .java2 s  .  c om
        retVal = new Vector<Long>(count);
        c.moveToFirst();

        for (int i = 0; i < count; i++) {
            retVal.add(c.getLong(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();
    return retVal;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static boolean isGroupSubscribed(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbread = dbhelper.getReadableDatabase();

    Cursor cur = dbread.rawQuery("SELECT _id FROM subscribed_groups WHERE _id=" + groupid, null);
    boolean ret = (cur.getCount() > 0);

    cur.close();//from   www  .java  2  s.co m
    dbread.close();
    dbhelper.close();
    return ret;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static boolean isAuthorFavorite(String author, Context context) {

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbread = dbhelper.getReadableDatabase();

    Cursor c = dbread.rawQuery("SELECT _id FROM favorite_users WHERE name=" + esc(author), null);

    boolean res = (c.getCount() > 0);

    c.close();//from   ww  w  .  j  a  v a2 s  .  c  om
    dbread.close();
    dbhelper.close();
    return res;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void banUser(String decodedfrom, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_users " + " WHERE name=" + esc(decodedfrom), null);

    if (c.getCount() > 0) {
        c.moveToFirst();//from   w  w  w .j a v  a 2 s .  c  om
        dbwrite.execSQL("UPDATE banned_users SET bandisabled=0 WHERE _id=" + c.getInt(0));
    } else {
        ContentValues cv = new ContentValues();
        cv.put("name", decodedfrom);
        cv.put("bandisabled", 0);
        dbwrite.insert("banned_users", null, cv);
    }

    // Mark all the user posts as read, so they get deleted later
    dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis()
            + " WHERE from_header=" + esc(decodedfrom));

    c.close();
    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static int getGroupUnreadCount(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbread = dbhelper.getReadableDatabase();

    Cursor c = dbread.rawQuery("SELECT _id FROM headers WHERE read=0 AND subscribed_group_id=" + groupid, null);
    int result = c.getCount();

    c.close();/*  ww w.  j  a va 2s  .co  m*/
    dbread.close();
    dbhelper.close();
    return result;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getStarredSubjectsSet(Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();
    Cursor c;

    String query = "SELECT clean_subject FROM starred_threads";
    c = dbread.rawQuery(query, null);/* w  w  w . j av a  2 s.  c  o  m*/
    HashSet<String> set = new HashSet<String>(c.getCount());

    c.moveToFirst();
    int count = c.getCount();
    for (int i = 0; i < count; i++) {
        set.add(c.getString(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();
    return set;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void logSentMessage(String msgId, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    /* Check first that the number of logged messages for this group is not greater than the 
    * limit impossed per group, because if it's greater we must delete number-limit older logs
    * until the table only has the limit. This is done this way because on the MessageList a set
    * is built with the post messages from that group, and then every loaded message's msgId is checked 
    * to see if it's in the set (to check for replies to our messages), so allowing it to grow too much
    * could make the MessageView slow//from   w w  w  .  java2  s  . co  m
    */

    Cursor c = dbwrite.rawQuery(
            "SELECT _id FROM sent_posts_log WHERE subscribed_group_id=" + groupid + " ORDER BY _id", null);
    int count = c.getCount();
    int toKill = count - UsenetConstants.SENT_POSTS_LOG_LIMIT_PER_GROUP;
    int kennyId;

    if (toKill > 0) {
        // Delete some more than needed so we don't have to do this on every post sent
        toKill += UsenetConstants.SENT_POST_KILL_ADITIONAL;
        c.moveToFirst();

        for (int i = 0; i < toKill; i++) {
            kennyId = c.getInt(0);
            dbwrite.execSQL("DELETE FROM sent_posts_log WHERE _id=" + kennyId);
            c.moveToNext();
        }
    }
    c.close();

    // Now we have room for sure, insert the log
    ContentValues cv = new ContentValues(2);
    cv.put("server_article_id", msgId);
    cv.put("subscribed_group_id", groupid);
    dbwrite.insert("sent_posts_log", null, cv);

    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void banThread(String group, String clean_subject, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    // First, check if it already is on the banned_threads table (it could be with unbanned=1)
    Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_threads " + " WHERE subscribed_group_id=" + groupid
            + " AND clean_subject=" + esc(clean_subject), null);

    if (c.getCount() > 0) { // Existed
        c.moveToFirst();/*from   w ww  .ja  v a 2s. co  m*/
        dbwrite.execSQL("UPDATE banned_threads SET bandisabled=0 WHERE _id=" + c.getInt(0));

    } else {
        // New troll goes down to the pit
        ContentValues cv = new ContentValues();
        cv.put("subscribed_group_id", groupid);
        cv.put("bandisabled", 0);
        cv.put("clean_subject", clean_subject);
        dbwrite.insert("banned_threads", null, cv);
    }

    // Mark all the messages from the thread as read so they get cleaned later
    dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis()
            + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject));

    c.close();
    dbwrite.close();
    db.close();
}