List of usage examples for android.content ContentValues putNull
public void putNull(String key)
From source file:Main.java
private static void writeLong(ContentValues values, String key, Long value) { if (value == null) { values.putNull(key); } else {// w w w . j a v a2 s . c o m values.put(key, value); } }
From source file:Main.java
private static void writeInteger(ContentValues values, String key, Integer value) { if (value == null) { values.putNull(key); } else {/* ww w . j ava 2 s .c om*/ values.put(key, value); } }
From source file:Main.java
private static void writeString(ContentValues values, String key, String value) { if (value == null) { values.putNull(key); } else {//w w w .j a va2 s .c om values.put(key, value); } }
From source file:Main.java
private static void safePut(ContentValues values, String key, String value) { if (value == null) { values.putNull(key); } else {// w w w.ja v a 2 s. c o m values.put(key, value); } }
From source file:Main.java
/** * Put an arbitrary object into a {@link ContentValues} * * @param target the ContentValues store * @param key the key to use//from w w w. j av a2 s .com * @param value the value to store */ public static void putInto(ContentValues target, String key, Object value, boolean errorOnFail) { if (value == null) { target.putNull(key); } else if (value instanceof Boolean) { target.put(key, (Boolean) value); } else if (value instanceof Byte) { target.put(key, (Byte) value); } else if (value instanceof Double) { target.put(key, (Double) value); } else if (value instanceof Float) { target.put(key, (Float) value); } else if (value instanceof Integer) { target.put(key, (Integer) value); } else if (value instanceof Long) { target.put(key, (Long) value); } else if (value instanceof Short) { target.put(key, (Short) value); } else if (value instanceof String) { target.put(key, (String) value); } else if (value instanceof byte[]) { target.put(key, (byte[]) value); } else if (errorOnFail) { throw new UnsupportedOperationException("Could not handle type " + value.getClass()); } }
From source file:com.lightydev.dk.json.Json.java
public static ContentValues parseObject(JSONObject object, Map<String, String> projection) throws JSONException { final ContentValues values = new ContentValues(); for (final Map.Entry<String, String> entry : projection.entrySet()) { if (object.has(entry.getValue())) { if (object.isNull(entry.getValue())) { values.putNull(entry.getKey()); } else { values.put(entry.getKey(), String.valueOf(object.get(entry.getValue()))); }//from w w w. j av a2 s.c o m } } return values; }
From source file:org.opendatakit.tables.utils.WebViewUtil.java
/** * Add a stringified value to the given content values. This respects the * column's type, as defined by {@link ColumnDefinition#getType()}. * * @param context/* w w w .j a va2 s .c om*/ * @param appName * @param tableId * @param du * @param colDefn * @param rawValue * @param contentValues * @return false if the data was invalid for the given type * @throws ServicesAvailabilityException */ public static boolean addValueToContentValues(Context context, String appName, String tableId, DateUtils du, // TableProperties tp, ColumnDefinition colDefn, String rawValue, ContentValues contentValues) throws ServicesAvailabilityException { // the value we're going to key things against in the database. String contentValuesKey = colDefn.getElementKey(); if (rawValue == null) { // Then we can trust that it is ok, as we allow nulls. // TODO: verify that nulls are permissible for the column? contentValues.putNull(contentValuesKey); return true; } else { // we have to validate it -- get the choices list, if any ArrayList<Map<String, Object>> choices; DbHandle db = null; try { db = Tables.getInstance().getDatabase().openDatabase(appName); choices = (ArrayList<Map<String, Object>>) ColumnUtil.get() .getDisplayChoicesList(Tables.getInstance(), appName, db, tableId, colDefn.getElementKey()); } finally { if (db != null) { Tables.getInstance().getDatabase().closeDatabase(appName, db); } } // we have to validate it. this validate function just returns null if // valid, rather than a boolean. String nullMeansInvalid = ParseUtil.validifyValue(appName, du, choices, colDefn, rawValue); if (nullMeansInvalid == null) { // return false, indicating that the value was not acceptable. WebLogger.getLogger(appName).e(TAG, "[addRow] could not parse [" + rawValue + "] for column [" + colDefn.getElementKey() + "] to type: " + colDefn.getType()); return false; } // This means all is well, and we can parse the value. ElementType columnType = colDefn.getType(); ElementTypeManipulator m = ElementTypeManipulatorFactory.getInstance(appName); ElementDataType type = columnType.getDataType(); if (type == ElementDataType.integer) { ElementTypeManipulator.ITypeManipulatorFragment<Integer> r; r = (ElementTypeManipulator.ITypeManipulatorFragment<Integer>) m.getDefaultRenderer(columnType); contentValues.put(contentValuesKey, r.parseStringValue(du, choices, rawValue, Integer.class)); } else if (type == ElementDataType.number) { ElementTypeManipulator.ITypeManipulatorFragment<Double> r; r = (ElementTypeManipulator.ITypeManipulatorFragment<Double>) m.getDefaultRenderer(columnType); contentValues.put(contentValuesKey, r.parseStringValue(du, choices, rawValue, Double.class)); } else if (type == ElementDataType.bool) { ElementTypeManipulator.ITypeManipulatorFragment<Integer> r; r = (ElementTypeManipulator.ITypeManipulatorFragment<Integer>) m.getDefaultRenderer(columnType); contentValues.put(contentValuesKey, (r.parseStringValue(du, choices, rawValue, Integer.class) == 0) ? Boolean.FALSE : Boolean.TRUE); } else { ElementTypeManipulator.ITypeManipulatorFragment<String> r; r = (ElementTypeManipulator.ITypeManipulatorFragment<String>) m.getDefaultRenderer(columnType); contentValues.put(contentValuesKey, r.parseStringValue(du, choices, rawValue, String.class)); } return true; } }
From source file:saphion.batterycaster.providers.Alarm.java
public static ContentValues createContentValues(Alarm alarm) { ContentValues values = new ContentValues(COLUMN_COUNT); if (alarm.id != INVALID_ID) { values.put(_ID, alarm.id);//w ww . j a v a 2 s .c om } values.put(ENABLED, alarm.enabled ? 1 : 0); values.put(BATTERY, alarm.battery); values.put(CHARGE, alarm.charge); values.put(DAYS_OF_WEEK, alarm.daysOfWeek.getBitSet()); values.put(VIBRATE, alarm.vibrate ? 1 : 0); values.put(LABEL, alarm.label); values.put(DELETE_AFTER_USE, alarm.deleteAfterUse); if (alarm.alert == null) { // We want to put null, so default alarm changes values.putNull(RINGTONE); } else { values.put(RINGTONE, alarm.alert.toString()); } return values; }
From source file:cn.figo.mydemo.content.RecentMediaStorage.java
public void saveUrl(String url) { ContentValues cv = new ContentValues(); cv.putNull(Entry.COLUMN_NAME_ID); cv.put(Entry.COLUMN_NAME_URL, url); cv.put(Entry.COLUMN_NAME_LAST_ACCESS, System.currentTimeMillis()); cv.put(Entry.COLUMN_NAME_NAME, getNameOfUrl(url)); save(cv);/* ww w. j a va 2 s. com*/ }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
public static void deleteStatus(@NonNull ContentResolver cr, @NonNull UserKey accountKey, @NonNull String statusId, @Nullable ParcelableStatus status) { final String host = accountKey.getHost(); final String deleteWhere, updateWhere; final String[] deleteWhereArgs, updateWhereArgs; if (host != null) { deleteWhere = Expression//w ww. j a v a 2 s . c o m .and(Expression.likeRaw(new Column(Statuses.ACCOUNT_KEY), "'%@'||?"), Expression.or( Expression.equalsArgs(Statuses.STATUS_ID), Expression.equalsArgs(Statuses.RETWEET_ID))) .getSQL(); deleteWhereArgs = new String[] { host, statusId, statusId }; updateWhere = Expression.and(Expression.likeRaw(new Column(Statuses.ACCOUNT_KEY), "'%@'||?"), Expression.equalsArgs(Statuses.MY_RETWEET_ID)).getSQL(); updateWhereArgs = new String[] { host, statusId }; } else { deleteWhere = Expression .or(Expression.equalsArgs(Statuses.STATUS_ID), Expression.equalsArgs(Statuses.RETWEET_ID)) .getSQL(); deleteWhereArgs = new String[] { statusId, statusId }; updateWhere = Expression.equalsArgs(Statuses.MY_RETWEET_ID).getSQL(); updateWhereArgs = new String[] { statusId }; } for (final Uri uri : STATUSES_URIS) { cr.delete(uri, deleteWhere, deleteWhereArgs); if (status != null) { final ContentValues values = new ContentValues(); values.putNull(Statuses.MY_RETWEET_ID); values.put(Statuses.RETWEET_COUNT, status.retweet_count - 1); cr.update(uri, values, updateWhere, updateWhereArgs); } } }