Example usage for android.database.sqlite SQLiteDatabase rawQuery

List of usage examples for android.database.sqlite SQLiteDatabase rawQuery

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase rawQuery.

Prototype

public Cursor rawQuery(String sql, String[] selectionArgs) 

Source Link

Document

Runs the provided SQL and returns a Cursor over the result set.

Usage

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 w  w  w  . j a v a 2 s.c o  m
    dbread.close();
    dbhelper.close();
    return ret;
}

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;// w  w w.j  ava2  s.  c  o 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 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  ww w  .j a  va  2s  . co m*/
        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 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 ww  .j  av  a  2s.  c  o  m
        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 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 www . ja va 2s . 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 Hashtable<String, Object> getHeaderRecordCatchedData(String group, long serverMsgNum,
        Context context) {//from w  ww  .j av a2  s  .  c  o m
    int groupid = getGroupIdFromName(group, context);

    Hashtable<String, Object> result = null;

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

    Cursor c = dbread.rawQuery("SELECT _id, server_article_id, catched FROM headers WHERE subscribed_group_id="
            + groupid + " AND server_article_number=" + serverMsgNum, null);

    if (c.getCount() == 1) {
        c.moveToFirst();

        result = new Hashtable<String, Object>(3);
        result.put("id", c.getInt(0));
        result.put("server_article_id", c.getString(1));
        if (c.getInt(2) == 1)
            result.put("catched", true);
        else
            result.put("catched", false);
    }

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

    return result;
}

From source file:com.hyunnyapp.easycursor.sqlcursor.querymodels.RawQueryModel.java

@Override
protected Cursor executeQueryInternal(final SQLiteDatabase db) {
    return db.rawQuery(mRawSql, mSelectionArgs);
}

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;/* w w w.  j av a2s  .  c o  m*/

    String query = "SELECT clean_subject FROM starred_threads";
    c = dbread.rawQuery(query, null);
    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 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();//  w  w  w.ja 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 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();//  ww w . j  a  v a  2 s . c o m
        dbread.close();
        db.close();
        return null;
    }

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

    return groupname;
}