本文整理了Java中android.database.Cursor.getCount()
方法的一些代码示例,展示了Cursor.getCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.getCount()
方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:getCount
暂无
代码示例来源:origin: stackoverflow.com
public boolean Exists(String _id) {
Cursor cursor = mDb.rawQuery("select 1 from yourTable where _id=%s",
new String[] { _id });
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
代码示例来源:origin: stackoverflow.com
Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
getContentResolver(), selectedImageUri,
MediaStore.Images.Thumbnails.MINI_KIND,
null );
if( cursor != null && cursor.getCount() > 0 ) {
cursor.moveToFirst();//**EDIT**
String uri = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) );
}
代码示例来源:origin: stackoverflow.com
public static int getOrientation(Context context, Uri photoUri) {
/* it's on the external media. */
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor.getCount() != 1) {
return -1;
}
cursor.moveToFirst();
return cursor.getInt(0);
}
代码示例来源:origin: cats-oss/android-gpuimage
@Override
protected int getImageOrientation() throws IOException {
Cursor cursor = context.getContentResolver().query(uri,
new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
if (cursor == null || cursor.getCount() != 1) {
return 0;
}
cursor.moveToFirst();
int orientation = cursor.getInt(0);
cursor.close();
return orientation;
}
}
代码示例来源:origin: greenrobot/greenDAO
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
public List<RelationSource2> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<RelationSource2> list = new ArrayList<RelationSource2>(count);
if (cursor.moveToFirst()) {
if (identityScope != null) {
identityScope.lock();
identityScope.reserveRoom(count);
}
try {
do {
list.add(loadCurrentDeep(cursor, false));
} while (cursor.moveToNext());
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
return list;
}
代码示例来源:origin: google/agera
@NonNull
@Override
public Result<List<T>> merge(@NonNull final SQLiteDatabase database,
@NonNull final SqlRequest input) {
try {
final Cursor cursor = database.rawQuery(input.sql, input.arguments);
try {
final int count = cursor.getCount();
if (count == 0) {
return success(Collections.<T>emptyList());
}
final List<T> items = new ArrayList<>(count);
while (cursor.moveToNext()) {
items.add(cursorToItem.apply(cursor));
}
return success(items);
} finally {
cursor.close();
}
} catch (final SQLException e) {
return failure(e);
}
}
}
代码示例来源:origin: stackoverflow.com
MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());
while (source.moveToNext()) {
MatrixCursor.RowBuilder row = cursor.newRow();
for (int i = 0; i < columnNames.length; i++) {
row.add(source.getString(i));
代码示例来源:origin: kaaproject/kaa
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);
}
}
}
代码示例来源:origin: stackoverflow.com
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;
}
}
}
代码示例来源:origin: stackoverflow.com
public String getContactDisplayNameByNumber(String number) {
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String name = "?";
ContentResolver contentResolver = getContentResolver();
Cursor contactLookup = contentResolver.query(uri, new String[] {BaseColumns._ID,
ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
try {
if (contactLookup != null && contactLookup.getCount() > 0) {
contactLookup.moveToNext();
name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
//String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
}
} finally {
if (contactLookup != null) {
contactLookup.close();
}
}
return name;
}
代码示例来源:origin: naman14/Timber
public static final int getSongCountForPlaylist(final Context context, final long playlistId) {
Cursor c = context.getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null);
if (c != null) {
int count = 0;
if (c.moveToFirst()) {
count = c.getCount();
}
c.close();
c = null;
return count;
}
return 0;
}
代码示例来源:origin: greenrobot/greenDAO
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
public List<RelationEntity> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<RelationEntity> list = new ArrayList<RelationEntity>(count);
if (cursor.moveToFirst()) {
if (identityScope != null) {
identityScope.lock();
identityScope.reserveRoom(count);
}
try {
do {
list.add(loadCurrentDeep(cursor, false));
} while (cursor.moveToNext());
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
return list;
}
代码示例来源:origin: stackoverflow.com
public int getProfilesCount() {
String countQuery = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int cnt = cursor.getCount();
cursor.close();
return cnt;
}
代码示例来源:origin: amitshekhariitbhu/Android-Debug-Database
public int count() {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("select * from cars", null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
return cursor.getInt(0);
} else {
return 0;
}
}
}
代码示例来源:origin: greenrobot/greenDAO
/** 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();
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
public ArrayList<FinishedMission> loadFinishedMissions() {
SQLiteDatabase database = downloadMissionHelper.getReadableDatabase();
Cursor cursor = database.query(MISSIONS_TABLE_NAME, null, null,
null, null, null, DownloadMissionHelper.KEY_TIMESTAMP);
int count = cursor.getCount();
if (count == 0) return new ArrayList<>(1);
ArrayList<FinishedMission> result = new ArrayList<>(count);
while (cursor.moveToNext()) {
result.add(DownloadMissionHelper.getMissionFromCursor(cursor));
}
return result;
}
代码示例来源:origin: stackoverflow.com
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(Contacts.CONTENT_URI,
null, null, null, null);
if(cur != null && cur.moveToFirst())
{
String id = cur.getString(cur.getColumnIndex(Contacts._ID));
if (cur.getCount() > 0) {
...
代码示例来源:origin: greenrobot/greenDAO
public TreeEntity loadDeep(Long key) {
assertSinglePk();
if (key == null) {
return null;
}
StringBuilder builder = new StringBuilder(getSelectDeep());
builder.append("WHERE ");
SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
String sql = builder.toString();
String[] keyArray = new String[] { key.toString() };
Cursor cursor = db.rawQuery(sql, keyArray);
try {
boolean available = cursor.moveToFirst();
if (!available) {
return null;
} else if (!cursor.isLast()) {
throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
}
return loadCurrentDeep(cursor, true);
} finally {
cursor.close();
}
}
代码示例来源:origin: greenrobot/greenDAO
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
public List<TreeEntity> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<TreeEntity> list = new ArrayList<TreeEntity>(count);
if (cursor.moveToFirst()) {
if (identityScope != null) {
identityScope.lock();
identityScope.reserveRoom(count);
}
try {
do {
list.add(loadCurrentDeep(cursor, false));
} while (cursor.moveToNext());
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
return list;
}
代码示例来源:origin: greenrobot/greenDAO
LazyList(InternalQueryDaoAccess<E> daoAccess, Cursor cursor, boolean cacheEntities) {
this.cursor = cursor;
this.daoAccess = daoAccess;
size = cursor.getCount();
if (cacheEntities) {
entities = new ArrayList<E>(size);
for (int i = 0; i < size; i++) {
entities.add(null);
}
} else {
entities = null;
}
if (size == 0) {
cursor.close();
}
lock = new ReentrantLock();
}
内容来源于网络,如有侵权,请联系作者删除!