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

The following examples show how to use android.database.Cursor#isNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Contracts.java    From UniFile with Apache License 2.0 6 votes vote down vote up
public 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 != null && c.moveToFirst() && !c.isNull(0)) {
            return c.getString(0);
        } else {
            return defaultValue;
        }
    } catch (Exception e) {
        return defaultValue;
    } finally {
        closeQuietly(c);
    }
}
 
Example 2
Source File: BaseDaoImpl.java    From RapidORM with Apache License 2.0 6 votes vote down vote up
@Deprecated
protected Object getObject(Cursor cursor, Class fieldType, int index) {
    if (null == cursor) {
        return null;
    }
    if (String.class == fieldType) {
        return cursor.getString(index);
    } else if (TypeUtil.isLongIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getLong(index);
    } else if (TypeUtil.isIntegerIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getInt(index);
    } else if (TypeUtil.isShortIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getShort(index);
    } else if (TypeUtil.isDoubleIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getDouble(index);
    } else if (TypeUtil.isFloatIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getFloat(index);
    } else if (TypeUtil.isBlobIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : cursor.getBlob(index);
    } else if (TypeUtil.isBooleanIncludePrimitive(fieldType)) {
        return cursor.isNull(index) ? null : (cursor.getInt(index) == 1);
    }
    return null;
}
 
Example 3
Source File: OC_FatController.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public static OC_User lastUserActiveFromDB(DBSQL db)
{
    Cursor cursor = db.prepareRawQuery(String.format("SELECT U.userid AS userid FROM %s AS U LEFT JOIN %s AS S ON S.userid = U.userid ORDER BY S.startTime DESC LIMIT 1",
            DBSQL.TABLE_USERS,DBSQL.TABLE_SESSIONS), null);
    int userId = -1;
    int columnIndex = cursor.getColumnIndex("userid");
    if(cursor.moveToFirst() && !cursor.isNull(columnIndex))
    {
        userId = cursor.getInt(columnIndex);
    }
    cursor.close();
    OC_User user = null;

    if(userId > -1)
        user = OC_User.UserFromDBForID(db, userId);

    return user;

}
 
Example 4
Source File: Green_AccountBeanDao.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
public Green_AccountBean readEntity(Cursor cursor, int offset) {
    Green_AccountBean entity = new Green_AccountBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // uid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // user_name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // user_password
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // cookie
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // oauth_token
            cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5), // oauth_token_expires_time
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // access_token_hack
            cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7), // expires_time_hack
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // g_sid
            cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9), // navigation_position
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // user_info_json
    );
    return entity;
}
 
Example 5
Source File: AttachmentDatabase.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: BoxedTypesPrivateFieldsIgnoreNullStorIOSQLiteGetResolver.java    From storio with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@NonNull
public BoxedTypesPrivateFieldsIgnoreNull mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {

    Boolean field1 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
        field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
    }
    Short field2 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
        field2 = cursor.getShort(cursor.getColumnIndex("field2"));
    }
    Integer field3 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
        field3 = cursor.getInt(cursor.getColumnIndex("field3"));
    }
    Long field4 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
        field4 = cursor.getLong(cursor.getColumnIndex("field4"));
    }
    Float field5 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
        field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
    }
    Double field6 = null;
    if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
        field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
    }

    BoxedTypesPrivateFieldsIgnoreNull object = new BoxedTypesPrivateFieldsIgnoreNull(field1, field2, field3, field4, field5, field6);

    return object;
}
 
Example 7
Source File: DatabaseHelper.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
public Location getLocation(long id) {
    SQLiteDatabase db = this.getReadableDatabase();
    String query = "SELECT * FROM location";
    query += " WHERE ID = " + id;

    Cursor cursor = null;
    try {
        cursor = db.rawQuery(query, new String[0]);
        if (cursor.moveToNext()) {
            int colTime = cursor.getColumnIndex("time");
            int colLatitude = cursor.getColumnIndex("latitude");
            int colLongitude = cursor.getColumnIndex("longitude");
            int colAltitude = cursor.getColumnIndex("altitude");
            int colAccuracy = cursor.getColumnIndex("accuracy");
            int colName = cursor.getColumnIndex("name");
            int colDeleted = cursor.getColumnIndex("deleted");

            Location location = new Location(cursor.getString(colName)); // hack
            location.setTime(cursor.isNull(colDeleted) ? cursor.getLong(colTime) : Long.MAX_VALUE);
            location.setLatitude(cursor.getDouble(colLatitude));
            location.setLongitude(cursor.getDouble(colLongitude));
            if (!cursor.isNull(colAltitude))
                location.setAltitude(cursor.getDouble(colAltitude));
            if (!cursor.isNull(colAccuracy))
                location.setAccuracy(cursor.getFloat(colAccuracy));
            return location;
        } else
            return null;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
 
Example 8
Source File: JokeCacheDao.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
/** @inheritdoc */
@Override
public JokeCache readEntity(Cursor cursor, int offset) {
    JokeCache entity = new JokeCache( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // result
        cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // page
        cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // time
    );
    return entity;
}
 
Example 9
Source File: VideoCacheDao.java    From JianDan with Apache License 2.0 5 votes vote down vote up
/** @inheritdoc */
@Override
public VideoCache readEntity(Cursor cursor, int offset) {
    VideoCache entity = new VideoCache( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // result
        cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // page
        cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // time
    );
    return entity;
}
 
Example 10
Source File: GroupsDao.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
public Groups readEntity(Cursor cursor, int offset) {
    Groups entity = new Groups( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // jid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getBlob(offset + 2) // participants
    );
    return entity;
}
 
Example 11
Source File: MusicInfoDao.java    From SweetMusicPlayer with Apache License 2.0 5 votes vote down vote up
/** @inheritdoc */
@Override
public MusicInfo readEntity(Cursor cursor, int offset) {
    MusicInfo entity = new MusicInfo( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // songId
        cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // albumId
        cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // artistId
        cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title
        cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // artist
        cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5), // duration
        cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // path
        cursor.isNull(offset + 7) ? null : cursor.getShort(offset + 7) != 0 // favorite
    );
    return entity;
}
 
Example 12
Source File: LiveCategoryDao.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
public LiveCategory readEntity(Cursor cursor, int offset) {
    LiveCategory entity = new LiveCategory( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.getInt(offset + 2), // is_default
        cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // slug
        cursor.getInt(offset + 4), // type
        cursor.getInt(offset + 5) // screen
    );
    return entity;
}
 
Example 13
Source File: JoinLettersWithAllophonesDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
@Override
public JoinLettersWithAllophones readEntity(Cursor cursor, int offset) {
    JoinLettersWithAllophones entity = new JoinLettersWithAllophones( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.getLong(offset + 1), // letterId
        cursor.getLong(offset + 2) // allophoneId
    );
    return entity;
}
 
Example 14
Source File: LikeBeanDao.java    From Ency with Apache License 2.0 4 votes vote down vote up
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 15
Source File: SearchAddDao.java    From Android-IM with Apache License 2.0 4 votes vote down vote up
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 16
Source File: ReadThreadDao.java    From TLint with Apache License 2.0 4 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 17
Source File: ChapterDao.java    From MissZzzReader with Apache License 2.0 4 votes vote down vote up
@Override
public String readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
}
 
Example 18
Source File: ShortColumnConverter.java    From volley with Apache License 2.0 4 votes vote down vote up
@Override
public Short getFieldValue(final Cursor cursor, int index) {
    return cursor.isNull(index) ? null : cursor.getShort(index);
}
 
Example 19
Source File: WordDao.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 20
Source File: SQLiteUtils.java    From tedroid with Apache License 2.0 2 votes vote down vote up
/**
 * @param cursor un objeto Cursor.
 * @param columnName el nombre de la columna.
 * @return el valor de la columna. Si no existe la columna o el valor de la columna es
 *         {@code null} entonces {@code null}.
 */
static String getString(Cursor cursor, String columnName) {
    return containsColumn(cursor, columnName) && !cursor.isNull(cursor.getColumnIndex(columnName))
            ? cursor.getString(cursor.getColumnIndex(columnName))
            : null;
}