Refine search
public static String getContactName(Context context, String phoneNumber) { ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null); if (cursor == null) { return null; } String contactName = null; if(cursor.moveToFirst()) { contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)); } if(cursor != null && !cursor.isClosed()) { cursor.close(); } return contactName; }
public Bitmap getImage(int i){ String qu = "select img from table where feedid=" + i ; Cursor cur = db.rawQuery(qu, null); if (cur.moveToFirst()){ byte[] imgByte = cur.getBlob(0); cur.close(); return BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length); } if (cur != null && !cur.isClosed()) { cur.close(); } return null ; }
public Account getCurrentAccount() { SQLiteDatabase db = dbHelper.getWritableDatabase(); String sql = "SELECT * FROM ACCOUNTS"; Cursor cursor = db.rawQuery(sql, new String[] {}); if(cursor.moveToFirst()){ this.accId = cursor.getInt(0); this.accName = cursor.getString(1); this.accImage = cursor.getBlob(2); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } db.close(); if(cursor.getCount() == 0){ return null; } else { return this; } }
public ArrayList<Object[]> _qaData(String where) { ArrayList<Object[]> data = new ArrayList<>(); Cursor cur = null; try { cur = mDb.getDatabase().query( "SELECT c.id, n.id, n.mid, c.did, c.ord, " + "n.tags, n.flds FROM cards c, notes n WHERE c.nid == n.id " + where, null); while (cur.moveToNext()) { data.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getLong(2), cur.getLong(3), cur.getInt(4), cur.getString(5), cur.getString(6) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } return data; }
/** * Field checksums and sorting fields *************************************** * ******************************************************** */ private ArrayList<Object[]> _fieldData(String snids) { ArrayList<Object[]> result = new ArrayList<>(); Cursor cur = null; try { cur = mDb.getDatabase().query("SELECT id, mid, flds FROM notes WHERE id IN " + snids, null); while (cur.moveToNext()) { result.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getString(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } return result; }
public TodayStats(SupportSQLiteDatabase db, long dayStartCutoff) { Cursor cur = null; String query = "select cards.did, "+ "sum(case when revlog.type = 0 then 1 else 0 end)"+ /* learning */ " from revlog, cards where revlog.cid = cards.id and revlog.id > " + dayStartCutoff + " group by cards.did"; Timber.d("AdvancedStatistics.TodayStats query: %s", query); try { cur = db.query(query, null); while(cur.moveToNext()) { nLearnedPerDeckId.put(cur.getLong(0), cur.getInt(1)); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } }
public static int getNotificationStatus(Context context) { openDBIfClosed(context); Cursor cursor = null; int due = 0; try { cursor = mMetaDb.query("smallWidgetStatus", new String[] { "due" }, null, null, null, null, null); if (cursor.moveToFirst()) { return cursor.getInt(0); } } catch (SQLiteException e) { Timber.e(e, "Error while querying widgetStatus"); } finally { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } return due; }
public String emptyCardReport(List<Long> cids) { StringBuilder rep = new StringBuilder(); Cursor cur = null; try { cur = mDb.getDatabase().query("select group_concat(ord+1), count(), flds from cards c, notes n " + "where c.nid = n.id and c.id in " + Utils.ids2str(cids) + " group by nid", null); while (cur.moveToNext()) { String ords = cur.getString(0); //int cnt = cur.getInt(1); // present but unused upstream as well String flds = cur.getString(2); rep.append(String.format("Empty card numbers: %s\nFields: %s\n\n", ords, flds.replace("\u001F", " / "))); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } return rep.toString(); }
/** * Return the current status of the widget. * * @return [due, eta] */ public static int[] getWidgetSmallStatus(Context context) { openDBIfClosed(context); Cursor cursor = null; try { cursor = mMetaDb.query("smallWidgetStatus", new String[] { "due", "eta" }, null, null, null, null, null); while (cursor.moveToNext()) { return new int[]{cursor.getInt(0), cursor.getInt(1)}; } } catch (SQLiteException e) { Timber.e(e, "Error while querying widgetStatus"); } finally { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } return new int[]{0, 0}; }
/** * Returns the state of the whiteboard for the given deck. * * @return 1 if the whiteboard should be shown, 0 otherwise */ public static boolean getWhiteboardState(Context context, long did) { openDBIfClosed(context); Cursor cur = null; try { cur = mMetaDb.rawQuery("SELECT state FROM whiteboardState" + " WHERE did = " + did, null); if (cur.moveToNext()) { return cur.getInt(0) > 0; } else { return false; } } catch (Exception e) { Timber.e(e, "Error retrieving whiteboard state from MetaDB "); return false; } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } }
/** * Returns a custom dictionary associated to a deck * * @return integer number of dictionary, -1 if not set (standard dictionary will be used) */ public static int getLookupDictionary(Context context, long did) { openDBIfClosed(context); Cursor cur = null; try { cur = mMetaDb.rawQuery("SELECT dictionary FROM customDictionary" + " WHERE did = " + did, null); if (cur.moveToNext()) { return cur.getInt(0); } else { return -1; } } catch (Exception e) { Timber.e(e, "Error retrieving custom dictionary from MetaDB "); return -1; } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } }