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 String getGroupNameFromId(int groupid, Context context) {

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

    String query = "SELECT name FROM subscribed_groups WHERE _id=" + groupid;
    Cursor cur = dbread.rawQuery(query, null);

    if (cur.getCount() != 1) {
        Log.w("GroundhogReader", "Trying to get name for groupid " + groupid + " which doesnt exists on DB");
        cur.close();/*  w  ww .j  a va  2s .co m*/
        dbread.close();
        db.close();
        return null;
    }

    cur.moveToFirst();
    String groupname = cur.getString(0);
    cur.close();
    dbread.close();
    db.close();

    return groupname;
}

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

public static int getGroupIdFromName(String group, Context context) {

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

    // First get the group ID
    String query = "SELECT _ID FROM subscribed_groups WHERE name=" + esc(group);
    Cursor cur = dbread.rawQuery(query, null);

    if (cur.getCount() != 1) { // WTF?? 
        Log.w("GroundhogReader", "Trying to get id for group named " + group + " which doesnt exists on DB");
        cur.close();/*from  w ww  .ja v  a2  s .  c  o  m*/
        dbread.close();
        db.close();
        return -1;
    }

    cur.moveToFirst();
    int groupid = cur.getInt(0);
    cur.close();
    dbread.close();
    db.close();

    return groupid;
}

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

public static HashSet<String> getBannedThreads(String group, Context context) {

    HashSet<String> bannedThreads = null;

    int groupid = getGroupIdFromName(group, context);

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

    String q = "SELECT clean_subject FROM banned_threads WHERE subscribed_group_id=" + groupid
            + " AND bandisabled=0";

    Cursor c = dbread.rawQuery(q, null);
    if (c.getCount() > 0) {

        bannedThreads = new HashSet<String>(c.getCount());
        c.moveToFirst();//from  w  ww.  ja v a 2  s .  c  o m

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

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

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

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

public static Vector<Object> isHeaderInDatabase(Long number, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

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

    String q = "SELECT _id, server_article_id FROM headers WHERE subscribed_group_id=" + groupid
            + " AND server_article_number=" + number;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        c.moveToFirst();//from  w  ww  . j a v a2 s .  c  o m
        retVal = new Vector<Object>(2);
        retVal.add(c.getLong(0));
        retVal.add(c.getString(1));
    }

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

    return retVal;
}

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

public static HashSet<String> getGroupSentMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

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

    String q = "SELECT server_article_id FROM sent_posts_log WHERE subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    retVal = new HashSet<String>(count);
    c.moveToFirst();//from  ww w .  java 2 s.c om

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

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

    return retVal;
}

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

public static Vector<Long> getUnreadNoncatchedArticleList(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

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

    String q = "SELECT server_article_number FROM headers WHERE subscribed_group_id=" + groupid
            + " AND read=0 AND catched=0";
    Cursor c = dbread.rawQuery(q, null);

    int count = c.getCount();
    artList = new Vector<Long>(count);

    c.moveToFirst();/*w ww  .  j  ava  2 s . c o m*/

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

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

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

public static HashSet<String> getReadMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    HashSet<String> readSet = null;

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

    String q = "SELECT server_article_id FROM headers WHERE read=1 AND subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        readSet = new HashSet<String>(c.getCount());
        c.moveToFirst();//from   w w  w . j  a  v  a  2 s .  com

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

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

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

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

public static void updateStarredThread(boolean starred, String clean_subject, int groupid, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbWrite = db.getWritableDatabase();

    clean_subject = clean_subject.replace("'", "''");

    String query;//w w w  . j  ava 2 s  .c o m

    if (starred == false) {
        query = "DELETE FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        dbWrite.execSQL(query);
    } else {
        // Check that it's not already on the table
        query = "SELECT _ID FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        Cursor c = dbWrite.rawQuery(query, null);

        if (c.getCount() == 0) {
            ContentValues cv = new ContentValues();
            cv.put("subscribed_group_id", groupid);
            cv.put("clean_subject", clean_subject);
            dbWrite.insert("starred_threads", null, cv);
        }
        c.close();
    }
    dbWrite.close();
    db.close();
}

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

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

    HashSet<String> bannedTrolls = null;

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

    String q = "SELECT name FROM banned_users WHERE bandisabled=0";

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    if (count > 0) {

        bannedTrolls = new HashSet<String>(c.getColumnCount());
        c.moveToFirst();//from w  w w. j  a  v a  2  s .c  o m

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

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

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

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

public static void expireReadMessages(Context context, boolean expireAll, long expireTime) {

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

    // Get all the expired messages so we can delete bodies and attachments
    long currentTime = System.currentTimeMillis();
    String q = null;/* w  w  w  .java  2 s  .co  m*/

    if (expireAll) {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1";
    } else {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    }

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    c.moveToFirst();
    String groupname;

    for (int i = 0; i < count; i++) {

        groupname = getGroupNameFromId(c.getInt(1) /*subscribed_group_id*/, context);
        FSUtils.deleteCacheMessage(c.getInt(0)/* _id */, groupname);

        if (c.getInt(2)/*has_attach*/ == 1) {
            FSUtils.deleteAttachments(c.getString(3) /*attachments_fnames*/, groupname);
        }

        c.moveToNext();
    }

    if (expireAll)
        q = "DELETE FROM headers WHERE read=1";
    else
        q = "DELETE FROM headers WHERE read=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    dbwrite.execSQL(q);
    c.close();
    dbwrite.close();
    db.close();
}