Refine search
@Override public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { int flaggedMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1", new String[] { Long.toString(databaseId) }, null, null, null); try { if (cursor.moveToFirst()) { flaggedMessageCount = cursor.getInt(0); } } finally { cursor.close(); } return flaggedMessageCount; } });
private static String replaceContentUriWithContentIdInHtmlPart( SQLiteDatabase db, long messageId, String htmlContent) { Cursor cursor = db.query("attachments", new String[] { "content_uri", "content_id" }, "content_id IS NOT NULL AND message_id = ?", new String[] { Long.toString(messageId) }, null, null, null); try { while (cursor.moveToNext()) { String contentUriString = cursor.getString(0); String contentId = cursor.getString(1); // this is not super efficient, but occurs only once or twice htmlContent = htmlContent.replace(contentUriString, "cid:" + contentId); } } finally { cursor.close(); } return htmlContent; }
public synchronized ArrayList<DownloadDBEntity> getDownLoadedListAll() { ArrayList<DownloadDBEntity> results = new ArrayList<>(); Cursor cursor = null; try { cursor = mMusicDatabase.getReadableDatabase().query(DownFileStoreColumns.NAME, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { results.ensureCapacity(cursor.getCount()); do { results.add(new DownloadDBEntity(cursor.getString(0), cursor.getLong(1), cursor.getLong(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getInt(7))); } while (cursor.moveToNext()); } return results; } finally { if (cursor != null) { cursor.close(); cursor = null; } } }
Cursor mCursor = database.query(true, EMP_TABLE,cols,null , null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst();
SQLiteDatabase db = dbHelper.getWritableDatabase(); public Cursor fetchByCountryCode(String strCountryCode) { /** * SELECT * FROM Country * WHERE code = US */ return cursor = db.query(true, "Country", /**< Table name. */ null, /**< All the fields that you want the cursor to contain; null means all.*/ "code=?", /**< WHERE statement without the WHERE clause. */ new String[] { strCountryCode }, /**< Selection arguments. */ null, null, null, null); } /** Fill a cursor with the results. */ Cursor c = fetchByCountryCode("US"); /** Retrieve data from the fields. */ String strCountryCode = c.getString(cursor.getColumnIndex("code")); /** Assuming that you have a field/column with the name "country_name" */ String strCountryName = c.getString(cursor.getColumnIndex("country_name"));
@Test public void testInsertAndQuery() throws Exception { String stringColumnValue = "column_value"; byte[] byteColumnValue = new byte[]{1, 2, 3}; ContentValues values = new ContentValues(); values.put("first_column", stringColumnValue); values.put("second_column", byteColumnValue); database.insert("table_name", null, values); Cursor cursor = database.query("table_name", new String[]{"second_column", "first_column"}, null, null, null, null, null); assertThat(cursor.moveToFirst()).isTrue(); byte[] byteValueFromDatabase = cursor.getBlob(0); String stringValueFromDatabase = cursor.getString(1); assertThat(stringValueFromDatabase).isEqualTo(stringColumnValue); assertThat(byteValueFromDatabase).isEqualTo(byteColumnValue); }
public synchronized String[] getDownLoadedListAllDowningIds() { ArrayList<String> results = new ArrayList<>(); Cursor cursor = null; try { cursor = mMusicDatabase.getReadableDatabase().query(DownFileStoreColumns.NAME, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { results.ensureCapacity(cursor.getCount()); do { if (cursor.getInt(7) != DownloadStatus.DOWNLOAD_STATUS_COMPLETED) results.add(cursor.getString(0)); } while (cursor.moveToNext()); } String[] t = new String[results.size()]; for (int i = 0; i < results.size(); i++) { t[i] = results.get(i); } return t; } finally { if (cursor != null) { cursor.close(); cursor = null; } } }
@Override public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { int unreadMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND read=0", new String[] { Long.toString(databaseId) }, null, null, null); try { if (cursor.moveToFirst()) { unreadMessageCount = cursor.getInt(0); } } finally { cursor.close(); } return unreadMessageCount; } });
private static MimeHeader loadHeaderFromHeadersTable(SQLiteDatabase db, long messageId) { Cursor headersCursor = db.query("headers", new String[] { "name", "value" }, "message_id = ?", new String[] { Long.toString(messageId) }, null, null, null); try { MimeHeader mimeHeader = new MimeHeader(); while (headersCursor.moveToNext()) { String name = headersCursor.getString(0); String value = headersCursor.getString(1); mimeHeader.addHeader(name, value); } return mimeHeader; } finally { headersCursor.close(); } }
public void loadTrack() { SQLiteDatabase db1 = waypoints.getWritableDatabase(); Cursor trackCursor = db1.query(TABLE_NAME, FROM, "trackidfk=1", null, null, null,ORDER_BY); trackCursor.moveToFirst(); do { Double lat = trackCursor.getDouble(2); Double lon = trackCursor.getDouble(1); //overlay.addGeoPoint( new GeoPoint( (int)(lat*1E6), (int)(lon*1E6))); System.out.println(lon); System.out.println(lat); } while (trackCursor.moveToNext()); }
@Override public List<PendingCommand> doDbWork(final SQLiteDatabase db) throws WrappedException { Cursor cursor = null; try { cursor = db.query("pending_commands", new String[] { "id", "command", "data" }, null, null, null, null, "id ASC"); List<PendingCommand> commands = new ArrayList<>(); while (cursor.moveToNext()) { long databaseId = cursor.getLong(0); String commandName = cursor.getString(1); String data = cursor.getString(2); PendingCommand command = pendingCommandSerializer.unserialize( databaseId, commandName, data); commands.add(command); } return commands; } finally { Utility.closeQuietly(cursor); } } });
@Test public void shouldCorrectlyReturnNullValues() { database.execSQL("CREATE TABLE null_test (col_int INTEGER, col_text TEXT, col_real REAL, col_blob BLOB)"); ContentValues data = new ContentValues(); data.putNull("col_int"); data.putNull("col_text"); data.putNull("col_real"); data.putNull("col_blob"); assertThat(database.insert("null_test", null, data)).isAtLeast(0L); Cursor nullValuesCursor = database.query("null_test", null, null, null, null, null, null); nullValuesCursor.moveToFirst(); final int colsCount = 4; for (int i = 0; i < colsCount; i++) { assertThat(nullValuesCursor.getType(i)).isEqualTo(Cursor.FIELD_TYPE_NULL); assertThat(nullValuesCursor.getString(i)).isNull(); } assertThat(nullValuesCursor.getBlob(3)).isNull(); }
public synchronized ArrayList<Playlist> getNetPlaylist() { ArrayList<Playlist> results = new ArrayList<>(); Cursor cursor = null; try { cursor = mMusicDatabase.getReadableDatabase().query(PlaylistInfoColumns.NAME, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { results.ensureCapacity(cursor.getCount()); do { if (!cursor.getString(4).equals("local")) results.add(new Playlist(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getString(3), cursor.getString(4))); } while (cursor.moveToNext()); } return results; } finally { if (cursor != null) { cursor.close(); cursor = null; } } }
public synchronized boolean getFav(long id) { Cursor cursor = null; try { cursor = mMusicDatabase.getReadableDatabase().query(PlaylistsColumns.NAME, null, PlaylistsColumns.PLAYLIST_ID + " = ?" + " AND " + PlaylistsColumns.TRACK_ID + " = ?", new String[]{favPlaylistId + "", id + ""}, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { return true; } return false; } finally { if (cursor != null) { cursor.close(); cursor = null; } } }
public List<SearchHistoryBean> queryAll() { Cursor cursor = db.query(SearchHistoryTable.TABLENAME, null, null, null, null, null, SearchHistoryTable.TIME + " desc"); List<SearchHistoryBean> list = new ArrayList<>(); while (cursor.moveToNext()) { SearchHistoryBean bean = new SearchHistoryBean(); bean.setKeyWord(cursor.getString(SearchHistoryTable.ID_KEYWORD)); bean.setTime(cursor.getString(SearchHistoryTable.ID_TIME)); list.add(bean); } cursor.close(); return list; }
public boolean isRead(String table, String key, int value) { boolean isRead = false; Cursor cursor = mSQLiteDatabase.query(table, null, "key=?", new String[]{key}, null, null, null); if (cursor.moveToNext() && (cursor.getInt(cursor.getColumnIndex("is_read")) == value)) { isRead = true; } cursor.close(); return isRead; }
private LocalMessage loadLocalMessageByRootPartId(SQLiteDatabase db, String rootPart) throws MessagingException { Cursor cursor = db.query("messages", new String[] { "id" }, "message_part_id = ?", new String[] { rootPart }, null, null, null); long messageId; try { if (!cursor.moveToFirst()) { return null; } messageId = cursor.getLong(0); } finally { Utility.closeQuietly(cursor); } return loadLocalMessageByMessageId(messageId); }
private String readValue(SQLiteDatabase mDb, String key) { Cursor cursor = null; String value = null; try { cursor = mDb.query( "preferences_storage", new String[] {"value"}, "primkey = ?", new String[] {key}, null, null, null); if (cursor.moveToNext()) { value = cursor.getString(0); Timber.d("Loading key '%s', value = '%s'", key, value); } } finally { Utility.closeQuietly(cursor); } return value; }