@Override public int compare(Cursor cursor1, Cursor cursor2) { if (mIdColumn == -1) { mIdColumn = cursor1.getColumnIndex("_id"); } long o1Id = cursor1.getLong(mIdColumn); long o2Id = cursor2.getLong(mIdColumn); return (o1Id > o2Id) ? -1 : 1; } }
public static Item valueOf(Cursor cursor) { return new Item(cursor.getLong(cursor.getColumnIndex(MediaStore.Files.FileColumns._ID)), cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE)), cursor.getLong(cursor.getColumnIndex(MediaStore.MediaColumns.SIZE)), cursor.getLong(cursor.getColumnIndex("duration"))); }
String query = "SELECT ROWID from MYTABLE order by ROWID DESC limit 1"; Cursor c = db.rawQuery(query); if (c != null && c.moveToFirst()) { lastId = c.getLong(0); //The 0 is the column index, we only have 1 column, so the index is 0 }
public static List<Album> getAlbumsForCursor(Cursor cursor) { ArrayList arrayList = new ArrayList(); if ((cursor != null) && (cursor.moveToFirst())) do { arrayList.add(new Album(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getLong(3), cursor.getInt(4), cursor.getInt(5))); } while (cursor.moveToNext()); if (cursor != null) cursor.close(); return arrayList; }
@Override public RelationEntity readEntity(Cursor cursor, int offset) { RelationEntity entity = new RelationEntity( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // parentId cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // testId cursor.getLong(offset + 3), // testIdNotNull cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // simpleString ); return entity; }
public static FinishedMission getMissionFromCursor(Cursor cursor) { if (cursor == null) throw new NullPointerException("cursor is null"); String kind = cursor.getString(cursor.getColumnIndex(KEY_KIND)); if (kind == null || kind.isEmpty()) kind = "?"; FinishedMission mission = new FinishedMission(); mission.name = cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME)); mission.location = cursor.getString(cursor.getColumnIndexOrThrow(KEY_LOCATION)); mission.source = cursor.getString(cursor.getColumnIndexOrThrow(KEY_SOURCE_URL));; mission.length = cursor.getLong(cursor.getColumnIndexOrThrow(KEY_DONE)); mission.timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(KEY_TIMESTAMP)); mission.kind = kind.charAt(0); return mission; } }
private void cleanupSelected(Cursor cursor) { if (selected.isEmpty()) { return; } Set<Long> selected = new HashSet<>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { long uniqueId = cursor.getLong(uniqueIdColumn); if (this.selected.contains(uniqueId)) { selected.add(uniqueId); } } this.selected = selected; }
private long getAffectedRowCount() { synchronized (database) { Cursor cursor = null; try { cursor = database.rawQuery(GET_CHANGES_QUERY, null); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { return cursor.getLong(cursor.getColumnIndex(CHANGES_QUERY_RESULT)); } else { return 0; } } finally { tryCloseCursor(cursor); } } }
/** Returns the count (number of results matching the query). Uses SELECT COUNT (*) sematics. */ public long count() { checkThread(); Cursor cursor = dao.getDatabase().rawQuery(sql, parameters); try { if (!cursor.moveToNext()) { throw new DaoException("No result for count"); } else if (!cursor.isLast()) { throw new DaoException("Unexpected row count: " + cursor.getCount()); } else if (cursor.getColumnCount() != 1) { throw new DaoException("Unexpected column count: " + cursor.getColumnCount()); } return cursor.getLong(0); } finally { cursor.close(); } }
int rotation =-1; long fileSize = new File(filePath).length(); Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(captureTime/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc"); if (mediaCursor != null && captureTime != 0 && mediaCursor.getCount() !=0 ) { while(mediaCursor.moveToNext()){ long size = mediaCursor.getLong(1); //Extra check to make sure that we are getting the orientation from the proper file if(size == fileSize){ rotation = mediaCursor.getInt(0); break; } } }
public static List<Artist> getArtistsForCursor(Cursor cursor) { ArrayList arrayList = new ArrayList(); if ((cursor != null) && (cursor.moveToFirst())) do { arrayList.add(new Artist(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3))); } while (cursor.moveToNext()); if (cursor != null) cursor.close(); return arrayList; }
@Override public ToManyTargetEntity readEntity(Cursor cursor, int offset) { ToManyTargetEntity entity = new ToManyTargetEntity( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // toManyId cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // toManyIdDesc cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // id cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // targetJoinProperty ); return entity; }
public Person get(int position) { Cursor cursor = getCursor(); Person person; if(cursor.moveToPosition(position)) { person = new Person(); person.id = cursor.getLong(cursor.getColumnIndex("_id")); person.firstName = cursor.getString(cursor.getColumnIndex("firstName")); person.surname = cursor.getString(cursor.getColumnIndex("surname")); results.add(person); } return person; }
String[] proj = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DATA }; Cursor cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, MediaStore.Video.Media.DISPLAY_NAME+"=?",new String[] {"name.mp4"}, null); cursor.moveToFirst() fileid = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));
@Test public void shouldStoreGreatBigHonkingIntegersCorrectly() throws Exception { database.execSQL("INSERT INTO table_name(big_int) VALUES(1234567890123456789);"); Cursor cursor = database.query("table_name", new String[]{"big_int"}, null, null, null, null, null); assertThat(cursor.moveToFirst()).isTrue(); assertEquals(1234567890123456789L, cursor.getLong(0)); }
public static long getLong(Cursor cursor, String column, long defValue) { try { int index = cursor.getColumnIndex(column); if (index != -1) { return cursor.getLong(index); } } catch (Throwable e) { /* Ignore */ } return defValue; }
@Test public void shouldBeAbleToMakeQueriesWithSelection() { Cursor cursor = builder.query(database, new String[] {"rowid"}, COL_VALUE + "=?", new String[] {"record1"}, null, null, null); assertThat(cursor.getCount()).isEqualTo(1); assertThat(cursor.moveToNext()).isTrue(); assertThat(cursor.getLong(0)).isEqualTo(firstRecordId); }
Uri returnUri = returnIntent.getData(); String mimeType = getContentResolver().getType(returnUri); Cursor returnCursor = getContentResolver().query(returnUri, null, null, null, null); int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE); returnCursor.moveToFirst(); TextView nameView = (TextView) findViewById(R.id.filename_text); TextView sizeView = (TextView) findViewById(R.id.filesize_text); nameView.setText(returnCursor.getString(nameIndex)); sizeView.setText(Long.toString(returnCursor.getLong(sizeIndex)));
@Override public void readEntity(Cursor cursor, RelationEntity entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setParentId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); entity.setTestId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); entity.setTestIdNotNull(cursor.getLong(offset + 3)); entity.setSimpleString(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); }
@Override public void onBindViewHolder(GuestViewHolder holder, int position) { // Move the mCursor to the position of the item to be displayed if (!mCursor.moveToPosition(position)) return; // bail if returned null // Update the view holder with the information needed to display String name = mCursor.getString(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME)); int partySize = mCursor.getInt(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE)); // COMPLETED (6) Retrieve the id from the cursor and long id = mCursor.getLong(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry._ID)); // Display the guest name holder.nameTextView.setText(name); // Display the party count holder.partySizeTextView.setText(String.valueOf(partySize)); // COMPLETED (7) Set the tag of the itemview in the holder to the id holder.itemView.setTag(id); }