Java Code Examples for android.database.Cursor.isNull()

The following are Jave code examples for showing how to use isNull() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: boohee_v5.6   File: DocumentsContractApi19.java   Source Code and License Vote up 6 votes
private static String queryForString(Context context, Uri self, String column, String defaultValue) {
    Cursor c = null;
    try {
        c = context.getContentResolver().query(self, new String[]{column}, null, null, null);
        if (!c.moveToFirst() || c.isNull(0)) {
            closeQuietly(c);
            return defaultValue;
        }
        defaultValue = c.getString(0);
        return defaultValue;
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
    } finally {
        closeQuietly(c);
    }
}
 
Example 2
Project: simple-share-android   File: DocumentsContractCompat.java   Source Code and License Vote up 6 votes
private static String queryForString(Context context, Uri self, String column,
        String defaultValue) {
    final ContentResolver resolver = context.getContentResolver();

    Cursor c = null;
    try {
        c = resolver.query(self, new String[] { column }, null, null, null);
        if (c.moveToFirst() && !c.isNull(0)) {
            return c.getString(0);
        } else {
            return defaultValue;
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
        return defaultValue;
    } finally {
        closeQuietly(c);
    }
}
 
Example 3
Project: KomaMusic   File: MusicUtils.java   Source Code and License Vote up 6 votes
/**
 * @param context The {@link Context} to use.
 * @param id      The id of the album.
 * @return The song count for an album.
 */
public static final int getSongCountForAlbumInt(final Context context, final long id) {
    int songCount = 0;
    if (id == -1) {
        return songCount;
    }

    Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
    Cursor cursor = context.getContentResolver().query(uri,
            new String[]{AlbumColumns.NUMBER_OF_SONGS}, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            if (!cursor.isNull(0)) {
                songCount = cursor.getInt(0);
            }
        }
        cursor.close();
        cursor = null;
    }

    return songCount;
}
 
Example 4
Project: Cable-Android   File: AttachmentDatabase.java   Source Code and License Vote up 6 votes
private @Nullable File getAttachmentDataFile(@NonNull AttachmentId attachmentId,
                                             @NonNull String dataType)
{
  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, new String[]{dataType}, PART_ID_WHERE, attachmentId.toStrings(),
                            null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      if (cursor.isNull(0)) {
        return null;
      }

      return new File(cursor.getString(0));
    } else {
      return null;
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }

}
 
Example 5
Project: FireFiles   File: DocumentsContractApi19.java   Source Code and License Vote up 6 votes
private static String queryForString(Context context, Uri self, String column,
        String defaultValue) {
    final ContentResolver resolver = context.getContentResolver();

    Cursor c = null;
    try {
        c = resolver.query(self, new String[] { column }, null, null, null);
        if (c.moveToFirst() && !c.isNull(0)) {
            return c.getString(0);
        } else {
            return defaultValue;
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
        return defaultValue;
    } finally {
        closeQuietly(c);
    }
}
 
Example 6
Project: GitHub   File: KeepEntityDao.java   Source Code and License Vote up 5 votes
@Override
public KeepEntity readEntity(Cursor cursor, int offset) {
    KeepEntity entity = new KeepEntity( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0) // id
    );
    return entity;
}
 
Example 7
Project: Cable-Android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addIntToStatement(SQLiteStatement statement, Cursor cursor,
                                      int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindLong(index, cursor.getLong(columnIndex));
  }
}
 
Example 8
Project: OpenHub   File: LocalUserDao.java   Source Code and License Vote up 5 votes
@Override
public LocalUser readEntity(Cursor cursor, int offset) {
    LocalUser entity = new LocalUser( //
        cursor.getString(offset + 0), // login
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // avatarUrl
        cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // followers
        cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4) // following
    );
    return entity;
}
 
Example 9
Project: OpenHub   File: TraceDao.java   Source Code and License Vote up 5 votes
@Override
public Trace readEntity(Cursor cursor, int offset) {
    Trace entity = new Trace( //
        cursor.getString(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // type
        cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId
        cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3), // repoId
        cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // startTime
        cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // latestTime
        cursor.isNull(offset + 6) ? null : cursor.getInt(offset + 6) // traceNum
    );
    return entity;
}
 
Example 10
Project: GitHub   File: SqliteMasterDao.java   Source Code and License Vote up 5 votes
@Override
public SqliteMaster readEntity(Cursor cursor, int offset) {
    SqliteMaster entity = new SqliteMaster( //
        cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // type
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // tableName
        cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3), // rootpage
        cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // sql
    );
    return entity;
}
 
Example 11
Project: Shopping_List   File: StatisticDao.java   Source Code and License Vote up 5 votes
@Override
public Statistic readEntity(Cursor cursor, int offset) {
    Statistic entity = new Statistic( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.getString(offset + 1), // name
        cursor.getDouble(offset + 2), // quantity
        cursor.getDouble(offset + 3), // totalCost
        cursor.getShort(offset + 4) != 0, // unit
        cursor.getLong(offset + 5) // date
    );
    return entity;
}
 
Example 12
Project: AndroidBackendlessChat   File: BUserDao.java   Source Code and License Vote up 5 votes
/** @inheritdoc */
@Override
public BUser readEntity(Cursor cursor, int offset) {
    BUser entity = new BUser( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // entityID
        cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // AuthenticationType
        cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // messageColor
        cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // lastOnline
        cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // lastUpdated
        cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6) != 0, // Online
        cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // Metadata
    );
    return entity;
}
 
Example 13
Project: GitHub   File: ToManyTargetEntityDao.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 14
Project: PeSanKita-android   File: ThreadDatabase.java   Source Code and License Vote up 5 votes
private @Nullable Uri getSnippetUri(Cursor cursor) {
  if (cursor.isNull(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI))) {
    return null;
  }

  try {
    return Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI)));
  } catch (IllegalArgumentException e) {
    Log.w(TAG, e);
    return null;
  }
}
 
Example 15
Project: GitHub   File: AnActiveEntityDao.java   Source Code and License Vote up 4 votes
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 16
Project: NotifyTools   File: UserDao.java   Source Code and License Vote up 4 votes
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 17
Project: chat-sdk-android-push-firebase   File: FollowerLinkDao.java   Source Code and License Vote up 4 votes
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 18
Project: sctalk   File: GroupDao.java   Source Code and License Vote up 4 votes
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 19
Project: q-mail   File: RecipientLoader.java   Source Code and License Vote up 4 votes
private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients,
        Map<String, Recipient> recipientMap, @Nullable String prefilledName) {

    while (cursor.moveToNext()) {
        String name = prefilledName != null ? prefilledName : cursor.getString(INDEX_NAME);

        String email = cursor.getString(INDEX_EMAIL);
        long contactId = cursor.getLong(INDEX_CONTACT_ID);
        String lookupKey = cursor.getString(INDEX_LOOKUP_KEY);

        // already exists? just skip then
        if (recipientMap.containsKey(email)) {
            // TODO merge? do something else? what do we do?
            continue;
        }

        int addressType = cursor.getInt(INDEX_EMAIL_TYPE);
        String addressLabel = null;
        switch (addressType) {
            case ContactsContract.CommonDataKinds.Email.TYPE_HOME: {
                addressLabel = getContext().getString(R.string.address_type_home);
                break;
            }
            case ContactsContract.CommonDataKinds.Email.TYPE_WORK: {
                addressLabel = getContext().getString(R.string.address_type_work);
                break;
            }
            case ContactsContract.CommonDataKinds.Email.TYPE_OTHER: {
                addressLabel = getContext().getString(R.string.address_type_other);
                break;
            }
            case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE: {
                // mobile isn't listed as an option contacts app, but it has a constant so we better support it
                addressLabel = getContext().getString(R.string.address_type_mobile);
                break;
            }
            case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM: {
                addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL);
                break;
            }
        }

        Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey);
        if (recipient.isValidEmailAddress()) {
            Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));

            recipient.photoThumbnailUri = photoUri;
            recipientMap.put(email, recipient);
            recipients.add(recipient);
        }
    }

    cursor.close();
}
 
Example 20
Project: MKAPP   File: DatabaseHelper.java   Source Code and License Vote up 4 votes
public void updateUsage(Usage usage, String dname) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            // There is a segmented index on uid, version, protocol, daddr and dport
            String selection = "uid = ? AND version = ? AND protocol = ? AND daddr = ? AND dport = ?";
            String[] selectionArgs = new String[]{
                    Integer.toString(usage.Uid),
                    Integer.toString(usage.Version),
                    Integer.toString(usage.Protocol),
                    dname == null ? usage.DAddr : dname,
                    Integer.toString(usage.DPort)
            };

            Cursor cursor = db.query("access", new String[]{"sent", "received", "connections"}, selection, selectionArgs, null, null, null);
            long sent = 0;
            long received = 0;
            int connections = 0;
            int colSent = cursor.getColumnIndex("sent");
            int colReceived = cursor.getColumnIndex("received");
            int colConnections = cursor.getColumnIndex("connections");
            if (cursor.moveToNext()) {
                sent = cursor.isNull(colSent) ? 0 : cursor.getLong(colSent);
                received = cursor.isNull(colReceived) ? 0 : cursor.getLong(colReceived);
                connections = cursor.isNull(colConnections) ? 0 : cursor.getInt(colConnections);
            }
            cursor.close();

            ContentValues cv = new ContentValues();
            cv.put("sent", sent + usage.Sent);
            cv.put("received", received + usage.Received);
            cv.put("connections", connections + 1);

            int rows = db.update("access", cv, selection, selectionArgs);
            if (rows != 1)
                Log.e(TAG, "Update usage failed rows=" + rows);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
}