List of usage examples for android.database Cursor isNull
boolean isNull(int columnIndex);
true
if the value in the indicated column is null. From source file:org.totschnig.myexpenses.provider.DbUtils.java
public static String getString(Cursor c, int columnIndex) { if (c.isNull(columnIndex)) return ""; return c.getString(columnIndex); }
From source file:edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
public static Uri toGeoUri(Cursor c) { if (c.isNull(c.getColumnIndex(Locatable.COL_LATITUDE)) || c.isNull(c.getColumnIndex(Locatable.COL_LONGITUDE))) { return null; }//from w w w .j a v a 2 s . com return Uri.parse("geo:" + c.getDouble(c.getColumnIndex(Locatable.COL_LATITUDE)) + "," + c.getDouble(c.getColumnIndex(Locatable.COL_LONGITUDE))); }
From source file:edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
/** * Get the latitude/longitude from the row currently selected in the cursor. Requires * LocatableUtils.Locatable._LATITUDE and LocatableUtils.Locatable._LONGITUDE to be selected. * * @param c/*ww w .ja va 2 s .co m*/ * @return */ public static Location toLocation(Cursor c, int latColumn, int lonColumn) { if (c.isNull(latColumn) || c.isNull(lonColumn)) { return null; } final Location l = new Location("internal"); l.setLatitude(c.getDouble(latColumn)); l.setLongitude(c.getDouble(lonColumn)); return l; }
From source file:edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
/** * Fills the result array with the current location. * * @param c//from www. j a va2 s .com * cursor pointing to row to get location of * @param result * output array. Must have 2 or more elements. Latitude is in index 0. */ public static void toLocationArray(Cursor c, int latColumn, int lonColumn, double[] result) { if (c.isNull(latColumn) || c.isNull(lonColumn)) { return; } result[0] = c.getDouble(latColumn); result[1] = c.getDouble(lonColumn); }
From source file:edu.mit.mobile.android.locast.data.Locatable.java
/** * Get the latitude/longitude from the row currently selected in the cursor. Requires Locatable.Columns._LATITUDE and Locatable.Columns._LONGITUDE to be selected. * @param c/*from w w w . java 2 s . co m*/ * @return */ public static Location toLocation(Cursor c) { final int lat_idx = c.getColumnIndex(Columns._LATITUDE); final int lon_idx = c.getColumnIndex(Columns._LONGITUDE); if (c.isNull(lat_idx) || c.isNull(lon_idx)) { return null; } final Location l = new Location("internal"); l.setLatitude(c.getDouble(lat_idx)); l.setLongitude(c.getDouble(lon_idx)); return l; }
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java
private static String queryForString(Context context, Uri self, String column, String defaultValue) { final ContentResolver resolver = context.getContentResolver(); Cursor c = null; try {/*from w w w . j a v a 2s. c o m*/ 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); } }
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java
private static long queryForLong(Context context, Uri self, String column, long defaultValue) { final ContentResolver resolver = context.getContentResolver(); Cursor c = null; try {/*from www . ja v a 2 s .co m*/ c = resolver.query(self, new String[] { column }, null, null, null); if (c.moveToFirst() && !c.isNull(0)) { return c.getLong(0); } else { return defaultValue; } } catch (Exception e) { Log.w(TAG, "Failed query: " + e); return defaultValue; } finally { closeQuietly(c); } }
From source file:edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
/** * Get the latitude/longitude from the row currently selected in the cursor. Requires * LocatableUtils.Locatable._LATITUDE and LocatableUtils.Locatable._LONGITUDE to be selected. * * @param c/*from w w w . j a v a2s . c o m*/ * @return */ public static Location toLocation(Cursor c) { final int lat_idx = c.getColumnIndex(Locatable.COL_LATITUDE); final int lon_idx = c.getColumnIndex(Locatable.COL_LONGITUDE); if (c.isNull(lat_idx) || c.isNull(lon_idx)) { return null; } final Location l = new Location("internal"); l.setLatitude(c.getDouble(lat_idx)); l.setLongitude(c.getDouble(lon_idx)); return l; }
From source file:org.opendatakit.common.android.utilities.ODKCursorUtils.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 whatever * data type it is./*from ww w . j ava 2 s.c o m*/ * <p> * This does not actually convert data types from one type to the other. * Instead, it safely preserves null values and returns boxed data values. If * you specify ArrayList or HashMap, it JSON deserializes the value into one * of those. * * @param c * @param clazz * @param i * @return */ @SuppressWarnings("unchecked") public static final <T> T getIndexAsType(Cursor c, Class<T> clazz, int i) { // If you add additional return types here be sure to modify the javadoc. try { if (i == -1) return null; if (c.isNull(i)) { return null; } if (clazz == Long.class) { Long l = c.getLong(i); return (T) l; } else if (clazz == Integer.class) { Integer l = c.getInt(i); return (T) l; } else if (clazz == Double.class) { Double d = c.getDouble(i); return (T) d; } else if (clazz == String.class) { String str = c.getString(i); return (T) str; } else if (clazz == Boolean.class) { // stored as integers Integer l = c.getInt(i); return (T) Boolean.valueOf(l != 0); } else if (clazz == ArrayList.class) { // json deserialization of an array String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, ArrayList.class); } else if (clazz == HashMap.class) { // json deserialization of an object String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, HashMap.class); } else { throw new IllegalStateException("Unexpected data type in SQLite table"); } } catch (ClassCastException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " in SQLite table "); } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } }
From source file:edu.mit.mobile.android.locast.data.CastMedia.java
public static Uri getThumbnail(Cursor c, int thumbCol, int thumbLocalCol) { Uri thumbnail;/*from ww w . j a v a 2 s . c o m*/ if (!c.isNull(thumbLocalCol)) { thumbnail = Uri.parse(c.getString(thumbLocalCol)); } else if (!c.isNull(thumbCol)) { thumbnail = Uri.parse(c.getString(thumbCol)); } else { thumbnail = null; } return thumbnail; }