android.database.Cursor.getInt()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(811)

本文整理了Java中android.database.Cursor.getInt()方法的一些代码示例,展示了Cursor.getInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.getInt()方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:getInt

Cursor.getInt介绍

[英]Returns the value of the requested column as an int.

The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [Integer.MIN_VALUE, Integer.MAX_VALUE] is implementation-defined.
[中]以int形式返回请求列的值。
结果以及当列值为null、列类型不是整数类型或整数值超出范围Integer.MIN_VALUEInteger.MAX_VALUE时,此方法是否引发异常是由实现定义的。

代码示例

代码示例来源:origin: stackoverflow.com

Cursor countCursor = getContentResolver().query(CONTENT_URI,
       new String[] {"count(*) AS count"},
       null,
       null,
       null);
   countCursor.moveToFirst();
   int count = countCursor.getInt(0);

代码示例来源:origin: stackoverflow.com

String selection = "_id = "+id;
Uri uri = Uri.parse("content://sms");
Cursor cursor = contentResolver.query(uri, null, selection, null, null);
String phone = cursor.getString(cursor.getColumnIndex("address"));
int type = cursor.getInt(cursor.getColumnIndex("type"));// 2 = sent, etc.
String date = cursor.getString(cursor.getColumnIndex("date"));
String body = cursor.getString(cursor.getColumnIndex("body"));

代码示例来源:origin: stackoverflow.com

Cursor mCount= db.rawQuery("select count(*) from users where uname='" + loginname + "' and pwd='" + loginpass +"'", null);
mCount.moveToFirst();
int count= mCount.getInt(0);
mCount.close();

代码示例来源:origin: stackoverflow.com

Cursor c = sampleDB.rawQuery("SELECT FirstName, Age FROM mytable " +
      "where Age > 10 LIMIT 5", null);

if (c != null ) {
  if  (c.moveToFirst()) {
    do {
      String firstName = c.getString(c.getColumnIndex("FirstName"));
      int age = c.getInt(c.getColumnIndex("Age"));
      results.add("" + firstName + ",Age: " + age);
    }while (c.moveToNext());
  }
}
c.close();

代码示例来源:origin: greenrobot/greenDAO

@Override
public TestEntity readEntity(Cursor cursor, int offset) {
  TestEntity entity = new TestEntity( //
    cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
    cursor.getInt(offset + 1), // simpleInt
    cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // simpleInteger
    cursor.getString(offset + 3), // simpleStringNotNull
    cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // simpleString
    cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // indexedString
    cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // indexedStringAscUnique
    cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)), // simpleDate
    cursor.isNull(offset + 8) ? null : cursor.getShort(offset + 8) != 0, // simpleBoolean
    cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9) // simpleByteArray
  );
  return entity;
}

代码示例来源:origin: k9mail/k-9

private void writeCursorPartsToOutputStream(SQLiteDatabase db, Cursor cursor, OutputStream outputStream)
    throws IOException, MessagingException {
  while (cursor.moveToNext()) {
    String partId = cursor.getString(ATTACH_PART_ID_INDEX);
    int location = cursor.getInt(ATTACH_LOCATION_INDEX);
    if (location == DataLocation.IN_DATABASE || location == DataLocation.ON_DISK) {
      writeSimplePartToOutputStream(partId, cursor, outputStream);
    } else if (location == DataLocation.CHILD_PART_CONTAINS_DATA) {
      writeRawBodyToStream(cursor, db, outputStream);
    }
  }
}

代码示例来源:origin: square/sqlbrite

@Override public Integer apply(Query query) {
  Cursor cursor = query.run();
  try {
   if (!cursor.moveToNext()) {
    throw new AssertionError("No rows");
   }
   return cursor.getInt(0);
  } finally {
   cursor.close();
  }
 }
});

代码示例来源:origin: commonsguy/cw-omnibus

private Uri getVideoUri(int position) {
  videos.moveToPosition(position);
  return(ContentUris.withAppendedId(
   MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
   videos.getInt(
    videos.getColumnIndex(MediaStore.Video.Media._ID))));
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testMoveToFirst() throws Exception {
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getInt(0)).isEqualTo(1234);
 assertThat(cursor.getString(1)).isEqualTo("Chuck");
}

代码示例来源:origin: stackoverflow.com

/**
 * Check if download was valid, see issue
 * http://code.google.com/p/android/issues/detail?id=18462
 * @param long1
 * @return
 */
private boolean validDownload(long downloadId) {

  Log.d(TAG,"Checking download status for id: " + downloadId);

  //Verify if download is a success
  Cursor c= dMgr.query(new DownloadManager.Query().setFilterById(downloadId));

  if(c.moveToFirst()){            
    int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));

    if(status == DownloadManager.STATUS_SUCCESSFUL){
      return true; //Download is valid, celebrate
    }else{
      int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
      Log.d(TAG, "Download not correct, status [" + status + "] reason [" + reason + "]");            
      return false;
    }   
  }               
  return false;                                   
}

代码示例来源:origin: greenrobot/greenDAO

public void testCursorQuerySimple() {
  insert(3);
  CursorQuery query = dao.queryBuilder().orderAsc(Properties.SimpleInteger).buildCursor();
  Cursor cursor = query.query();
  try {
    assertEquals(3, cursor.getCount());
    assertTrue(cursor.moveToNext());
    int columnIndex = cursor.getColumnIndexOrThrow(Properties.SimpleInteger.columnName);
    assertEquals(getSimpleInteger(0), cursor.getInt(columnIndex));
    assertTrue(cursor.moveToNext());
    assertEquals(getSimpleInteger(1), cursor.getInt(columnIndex));
    assertTrue(cursor.moveToNext());
    assertEquals(getSimpleInteger(2), cursor.getInt(columnIndex));
    assertFalse(cursor.moveToNext());
  } finally {
    cursor.close();
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetInt() throws Exception {
 assertThat(cursor.moveToFirst()).isTrue();
 int[] data = {1234, 1235, 1236};
 for (int aData : data) {
  assertThat(cursor.getInt(0)).isEqualTo(aData);
  cursor.moveToNext();
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testFailureNestedTransaction() throws Exception {
  database.beginTransaction();
  database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
  database.beginTransaction();
  database.execSQL("INSERT INTO table_name (id, name) VALUES(12345, 'Julie');");
  database.endTransaction();
  database.setTransactionSuccessful();
  database.endTransaction();
  Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM table_name", null);
  assertThat(cursor.moveToNext()).isTrue();
  assertThat(cursor.getInt(0)).isEqualTo(0);
}

代码示例来源:origin: naman14/Timber

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;
}

代码示例来源:origin: commonsguy/cw-omnibus

void bindModel(Cursor row) {
  int mimeTypeColumn=
    row.getColumnIndex(MediaStore.Video.Media.MIME_TYPE);

  videoUri=ContentUris.withAppendedId(
   MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
   row.getInt(row.getColumnIndex(MediaStore.Video.Media._ID)));
  videoMimeType=row.getString(mimeTypeColumn);
 }
}

代码示例来源:origin: square/picasso

@Override
protected int getExifOrientation(Uri uri) {
 Cursor cursor = null;
 try {
  ContentResolver contentResolver = context.getContentResolver();
  cursor = contentResolver.query(uri, CONTENT_ORIENTATION, null, null, null);
  if (cursor == null || !cursor.moveToFirst()) {
   return 0;
  }
  return cursor.getInt(0);
 } catch (RuntimeException ignored) {
  // If the orientation column doesn't exist, assume no rotation.
  return 0;
 } finally {
  if (cursor != null) {
   cursor.close();
  }
 }
}

代码示例来源:origin: greenrobot/greenDAO

@Override
public SpecialNamesEntity readEntity(Cursor cursor, int offset) {
  SpecialNamesEntity entity = new SpecialNamesEntity( //
    cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
    cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // count
    cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // select
    cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // sum
    cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // avg
    cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // join
    cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // distinct
    cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // on
    cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // index
    cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9) // order
  );
  return entity;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testFailureTransaction() throws Exception {
  database.beginTransaction();
  database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
  final String select = "SELECT COUNT(*) FROM table_name";
  Cursor cursor = database.rawQuery(select, null);
  assertThat(cursor.moveToNext()).isTrue();
  assertThat(cursor.getInt(0)).isEqualTo(1);
  cursor.close();
  database.endTransaction();
  cursor = database.rawQuery(select, null);
  assertThat(cursor.moveToNext()).isTrue();
  assertThat(cursor.getInt(0)).isEqualTo(0);
}

代码示例来源:origin: commonsguy/cw-omnibus

private Uri getVideoUri(int position) {
  videos.moveToPosition(position);
  return(ContentUris.withAppendedId(
   MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
   videos.getInt(videos.getColumnIndex(MediaStore.Video.Media._ID))));
 }
}

代码示例来源:origin: stackoverflow.com

Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
  orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}  
Matrix matrix = new Matrix();
matrix.postRotate(orientation);

相关文章