public static void cursorLongToContentValuesIfPresent(Cursor paramCursor, ContentValues paramContentValues, String paramString)
 {
   int i = paramCursor.getColumnIndex(paramString);
   if ((i != -1) && (!paramCursor.isNull(i))) {
     paramContentValues.put(paramString, Long.valueOf(paramCursor.getLong(i)));
   }
 }
 /**
  * Reads a Long out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the
  * ContentValues if the column isn't present or if its value is null.
  *
  * @param cursor The cursor to read from
  * @param column The column to read
  * @param values The {@link ContentValues} to put the value into
  */
 public static void cursorLongToContentValuesIfPresent(
     Cursor cursor, ContentValues values, String column) {
   final int index = cursor.getColumnIndexOrThrow(column);
   if (!cursor.isNull(index)) {
     values.put(column, cursor.getLong(index));
   }
 }
 /**
  * Query the table for the number of rows in the table.
  *
  * @param db the database the table is in
  * @param table the name of the table to query
  * @return the number of rows in the table
  */
 public static long queryNumEntries(SQLiteDatabase db, String table) {
   Cursor cursor = db.query(table, countProjection, null, null, null, null, null);
   try {
     cursor.moveToFirst();
     return cursor.getLong(0);
   } finally {
     cursor.close();
   }
 }
 public static void cursorLongToContentValues(Cursor paramCursor, String paramString1, ContentValues paramContentValues, String paramString2)
 {
   int i = paramCursor.getColumnIndex(paramString1);
   if (!paramCursor.isNull(i))
   {
     paramContentValues.put(paramString2, Long.valueOf(paramCursor.getLong(i)));
     return;
   }
   paramContentValues.put(paramString2, null);
 }
 /**
  * Reads a Long out of a field in a Cursor and writes it to a Map.
  *
  * @param cursor The cursor to read from
  * @param field The INTEGER field to read
  * @param values The {@link ContentValues} to put the value into
  * @param key The key to store the value with in the map
  */
 public static void cursorLongToContentValues(
     Cursor cursor, String field, ContentValues values, String key) {
   int colIndex = cursor.getColumnIndex(field);
   if (!cursor.isNull(colIndex)) {
     Long value = Long.valueOf(cursor.getLong(colIndex));
     values.put(key, value);
   } else {
     values.put(key, (Long) null);
   }
 }
Exemple #6
0
 @Test
 public void testGetLong() throws Exception {
   List<Field.Type> types = Arrays.asList(Field.Type.TYPE_LONG, Field.Type.TYPE_LONGLONG);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("12345")))
                 .build())) {
       cursor.next();
       Assert.assertEquals(12345L, cursor.getLong("col0"));
     }
   }
 }
 public static void cursorFillWindow(Cursor paramCursor, int paramInt, CursorWindow paramCursorWindow)
 {
   if ((paramInt < 0) || (paramInt >= paramCursor.getCount())) {
     return;
   }
   int j = paramCursor.getPosition();
   int k = paramCursor.getColumnCount();
   paramCursorWindow.clear();
   paramCursorWindow.setStartPosition(paramInt);
   paramCursorWindow.setNumColumns(k);
   int i;
   if (paramCursor.moveToPosition(paramInt)) {
     if (paramCursorWindow.allocRow()) {
       i = 0;
     }
   }
   for (;;)
   {
     Object localObject;
     boolean bool;
     if (i < k) {
       switch (paramCursor.getType(i))
       {
       case 3: 
       default: 
         localObject = paramCursor.getString(i);
         if (localObject != null) {
           bool = paramCursorWindow.putString((String)localObject, paramInt, i);
         }
         break;
       }
     }
     for (;;)
     {
       if (bool) {
         break label264;
       }
       paramCursorWindow.freeLastRow();
       paramInt += 1;
       if (paramCursor.moveToNext()) {
         break;
       }
       paramCursor.moveToPosition(j);
       return;
       bool = paramCursorWindow.putNull(paramInt, i);
       continue;
       bool = paramCursorWindow.putLong(paramCursor.getLong(i), paramInt, i);
       continue;
       bool = paramCursorWindow.putDouble(paramCursor.getDouble(i), paramInt, i);
       continue;
       localObject = paramCursor.getBlob(i);
       if (localObject != null)
       {
         bool = paramCursorWindow.putBlob((byte[])localObject, paramInt, i);
       }
       else
       {
         bool = paramCursorWindow.putNull(paramInt, i);
         continue;
         bool = paramCursorWindow.putNull(paramInt, i);
       }
     }
     label264:
     i += 1;
   }
 }
  public static void cursorFillWindow(
      final Cursor cursor, int position, final android.database.CursorWindow window) {
    if (position < 0 || position >= cursor.getCount()) {
      return;
    }
    final int oldPos = cursor.getPosition();
    final int numColumns = cursor.getColumnCount();
    window.clear();
    window.setStartPosition(position);
    window.setNumColumns(numColumns);
    if (cursor.moveToPosition(position)) {
      do {
        if (!window.allocRow()) {
          break;
        }
        for (int i = 0; i < numColumns; i++) {
          final int type = cursor.getType(i);
          final boolean success;
          switch (type) {
            case Cursor.FIELD_TYPE_NULL:
              success = window.putNull(position, i);
              break;

            case Cursor.FIELD_TYPE_INTEGER:
              success = window.putLong(cursor.getLong(i), position, i);
              break;

            case Cursor.FIELD_TYPE_FLOAT:
              success = window.putDouble(cursor.getDouble(i), position, i);
              break;

            case Cursor.FIELD_TYPE_BLOB:
              {
                final byte[] value = cursor.getBlob(i);
                success =
                    value != null
                        ? window.putBlob(value, position, i)
                        : window.putNull(position, i);
                break;
              }

            default: // assume value is convertible to String
            case Cursor.FIELD_TYPE_STRING:
              {
                final String value = cursor.getString(i);
                success =
                    value != null
                        ? window.putString(value, position, i)
                        : window.putNull(position, i);
                break;
              }
          }
          if (!success) {
            window.freeLastRow();
            break;
          }
        }
        position += 1;
      } while (cursor.moveToNext());
    }
    cursor.moveToPosition(oldPos);
  }