Example usage for android.database Cursor isNull

List of usage examples for android.database Cursor isNull

Introduction

In this page you can find the example usage for android.database Cursor isNull.

Prototype

boolean isNull(int columnIndex);

Source Link

Document

Returns true if the value in the indicated column is null.

Usage

From source file:Main.java

public static boolean boolFromCursor(Cursor c, String field) {
    if (c.isNull(c.getColumnIndex(field))) {
        return false;
    }/* ww  w.  jav  a  2 s  . c  o  m*/
    int val = c.getInt(c.getColumnIndex(field));
    return (val > 0) ? true : false;
}

From source file:Main.java

public static Date loadDate(Cursor cursor, int index) {
    if (cursor.isNull(index)) {
        return null;
    }/*from   www .j  ava2 s.  c om*/
    return new Date(cursor.getLong(index));
}

From source file:Main.java

private static String readString(Cursor cursor, int index) {
    return (cursor.isNull(index) ? null : cursor.getString(index));
}

From source file:Main.java

private static Integer readInteger(Cursor cursor, int index) {
    return (cursor.isNull(index) ? null : cursor.getInt(index));
}

From source file:Main.java

private static Long readLong(Cursor cursor, int index, Long defaultValue) {
    Long result = defaultValue;/*from   w ww  . j  ava  2 s.  c  o m*/
    if (!cursor.isNull(index)) {
        result = cursor.getLong(index);
    }
    return result;
}

From source file:edu.mit.mobile.android.locast.data.Locatable.java

public static Uri toGeoUri(Cursor c) {
    if (c.isNull(c.getColumnIndex(Columns._LATITUDE)) || c.isNull(c.getColumnIndex(Columns._LONGITUDE))) {
        return null;
    }//from w w  w .j  a  va  2s .  c  o  m
    return Uri.parse("geo:" + c.getDouble(c.getColumnIndex(Columns._LATITUDE)) + ","
            + c.getDouble(c.getColumnIndex(Columns._LONGITUDE)));
}

From source file:Main.java

/**
 * Return the data stored in the cursor at the given index and given position
 * (ie the given row which the cursor is currently on) as null OR a String.
 * <p>//from ww  w .j  av  a 2 s .c  o  m
 * NB: Currently only checks for Strings, long, int, and double.
 *
 * @param c
 * @param i
 * @return
 */
@SuppressLint("NewApi")
public static String getIndexAsString(Cursor c, int i) {
    // If you add additional return types here be sure to modify the javadoc.
    if (i == -1)
        return null;
    if (c.isNull(i)) {
        return null;
    }
    switch (c.getType(i)) {
    case Cursor.FIELD_TYPE_STRING:
        return c.getString(i);
    case Cursor.FIELD_TYPE_FLOAT: {
        // the static version of this seems to have problems...
        Double d = c.getDouble(i);
        String v = d.toString();
        return v;
    }
    case Cursor.FIELD_TYPE_INTEGER: {
        // the static version of this seems to have problems...
        Long l = c.getLong(i);
        String v = l.toString();
        return v;
    }
    case Cursor.FIELD_TYPE_NULL:
        return c.getString(i);
    default:
    case Cursor.FIELD_TYPE_BLOB:
        throw new IllegalStateException("Unexpected data type in SQLite table");
    }
}

From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java

public static Task getTask(Cursor cursor, TaskCursorIds c) {
    LatLng coords;/*from w ww  .  j  a  va2 s .  com*/

    coords = (cursor.isNull(c.latitude) || cursor.isNull(c.longitude)) ? null
            : new LatLng(cursor.getDouble(c.latitude), cursor.getDouble(c.longitude));

    try {
        List<AdditionalResource> res = null;
        String addRes = cursor.getString(c.additionalResources);
        if (addRes != null) {
            try {
                res = Serialization.getJsonInstance().readValue(addRes,
                        new TypeReference<List<AdditionalResource>>() {
                        });
            } catch (JsonProcessingException e) {
                Log.e("CursorConverters", "Could not read additional resources: " + addRes, e);
            }
        }

        return new Task(cursor.getInt(c.id), getBoolean(cursor, c.locationSpecific), coords,
                cursor.getDouble(c.radius), cursor.getString(c.name), cursor.getString(c.description),
                getBoolean(cursor, c.multiple), cursor.getInt(c.submitType), cursor.getString(c.points), res);
    } catch (IOException e) {
        Log.e("Task Cursor Converter", "Json deserialization failed", e);
        return null;
    }
}

From source file:org.totschnig.myexpenses.provider.DbUtils.java

public static Long getLongOrNull(Cursor c, int columnIndex) {
    if (c.isNull(columnIndex))
        return null;
    return c.getLong(columnIndex);
}

From source file:org.totschnig.myexpenses.provider.DbUtils.java

public static Long getLongOr0L(Cursor c, int columnIndex) {
    if (c.isNull(columnIndex))
        return 0L;
    return c.getLong(columnIndex);
}