List of usage examples for android.database.sqlite SQLiteDatabase rawQuery
public Cursor rawQuery(String sql, String[] selectionArgs)
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static long getGroupLastFetchedNumber(String group, Context context) { long lastFetched = -1; DBHelper dbhelper = new DBHelper(context); SQLiteDatabase readdb = dbhelper.getReadableDatabase(); String fQuery = "SELECT lastFetched FROM subscribed_groups WHERE name=" + esc(group); Cursor cur = readdb.rawQuery(fQuery, null); if (cur.getCount() > 0) { cur.moveToFirst();/* w w w . ja va 2 s . c om*/ lastFetched = cur.getInt(0); } cur.close(); readdb.close(); dbhelper.close(); return lastFetched; }
From source file:DictionaryDatabase.java
public String getDefinition(long id) { String returnVal = ""; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT definition FROM " + TABLE_DICTIONARY + " WHERE _id = ?", new String[] { String.valueOf(id) }); if (cursor.getCount() == 1) { cursor.moveToFirst();/*w w w . j a va 2s. c om*/ returnVal = cursor.getString(0); } return returnVal; }
From source file:DictionaryDatabase.java
public long findWordID(String word) { long returnVal = -1; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?", new String[] { word }); if (cursor.getCount() == 1) { cursor.moveToFirst();//from www . ja v a 2 s.c o m returnVal = cursor.getInt(0); } return returnVal; }
From source file:DictionaryDatabase.java
public long findWordID(String word) { long returnVal = -1; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?", new String[] { word }); Log.i("findWordID", "getCount()=" + cursor.getCount()); if (cursor.getCount() == 1) { cursor.moveToFirst();/* w ww . j a v a 2 s.com*/ returnVal = cursor.getInt(0); } return returnVal; }
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 . j av a 2s . c o m*/ 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 boolean groupHasUncatchedMessages(String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); String q = "SELECT _id FROM headers WHERE subscribed_group_id=" + groupid + " AND read=0 AND catched=0"; Cursor c = dbread.rawQuery(q, null); int count = c.getCount(); c.close();//from w w w . ja v a 2 s . com dbread.close(); db.close(); return (count > 0); }
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();// w w w .ja v a2 s. c om 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(); }
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();/*w w w . j av a 2 s. c o m*/ 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 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 www . j a 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();// w w w . 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; }