Example usage for android.content ContentValues putNull

List of usage examples for android.content ContentValues putNull

Introduction

In this page you can find the example usage for android.content ContentValues putNull.

Prototype

public void putNull(String key) 

Source Link

Document

Adds a null value to the set.

Usage

From source file:com.acrutiapps.browser.tasks.HistoryBookmarksImportTask.java

private ContentValues createContentValues(String title, String url, int visits, long visitedDate,
        long creationDate, int bookmark) {
    ContentValues values = new ContentValues();
    values.put(BookmarksProvider.Columns.TITLE, title);
    values.put(BookmarksProvider.Columns.URL, url);
    values.put(BookmarksProvider.Columns.VISITS, visits);

    if (visitedDate > 0) {
        values.put(BookmarksProvider.Columns.VISITED_DATE, visitedDate);
    } else {//from www . ja  v a  2 s.com
        values.putNull(BookmarksProvider.Columns.VISITED_DATE);
    }

    if (creationDate > 0) {
        values.put(BookmarksProvider.Columns.CREATION_DATE, creationDate);
    } else {
        values.putNull(BookmarksProvider.Columns.CREATION_DATE);
    }

    if (bookmark > 0) {
        values.put(BookmarksProvider.Columns.BOOKMARK, 1);
    } else {
        values.put(BookmarksProvider.Columns.BOOKMARK, 0);
    }

    return values;
}

From source file:ru.gkpromtech.exhibition.db.Table.java

private ContentValues itemToRow(T item) throws IllegalAccessException {
    ContentValues values = new ContentValues();

    for (int i = 0; i < mFields.length; ++i) {
        if (mFields[i].get(item) == null) {
            values.putNull(mColumns[i]);
            continue;
        }/*w  ww . j  ava  2  s.co m*/

        switch (mType[i]) {
        case INTEGER:
            values.put(mColumns[i], (Integer) mFields[i].get(item));
            break;
        case SHORT:
            values.put(mColumns[i], (Short) mFields[i].get(item));
            break;
        case LONG:
            values.put(mColumns[i], (Long) mFields[i].get(item));
            break;
        case FLOAT:
            values.put(mColumns[i], (Float) mFields[i].get(item));
            break;
        case DOUBLE:
            values.put(mColumns[i], (Double) mFields[i].get(item));
            break;
        case STRING:
            values.put(mColumns[i], (String) mFields[i].get(item));
            break;
        case BYTE_ARRAY:
            values.put(mColumns[i], (byte[]) mFields[i].get(item));
            break;
        case DATE:
            values.put(mColumns[i], ((Date) mFields[i].get(item)).getTime());
            break;
        case BOOLEAN:
            values.put(mColumns[i], mFields[i].getBoolean(item) ? 1 : 0);
            break;
        }
    }
    return values;
}

From source file:can.yrt.onebusaway.ArrivalsListFragment.java

@Override
public void setUserStopName(String name) {
    ContentResolver cr = getActivity().getContentResolver();
    ContentValues values = new ContentValues();
    if (TextUtils.isEmpty(name)) {
        values.putNull(ObaContract.Stops.USER_NAME);
        mStopUserName = null;//from   w  w  w.j av  a  2  s  . c o m
    } else {
        values.put(ObaContract.Stops.USER_NAME, name);
        mStopUserName = name;
    }
    cr.update(mStopUri, values, null, null);
}

From source file:ru.gkpromtech.exhibition.db.Table.java

private ContentValues jsonToRow(ObjectNode object) throws IllegalAccessException, ParseException {
    ContentValues values = new ContentValues();

    for (int i = 0; i < mFields.length; ++i) {
        String fieldName = mFields[i].getName();
        JsonNode field = object.get(fieldName);
        if (field == null)
            continue;
        if (field.isNull()) {
            values.putNull(mColumns[i]);
            continue;
        }/*w ww.  j  a va 2  s.  c  om*/

        switch (mType[i]) {
        case INTEGER:
            values.put(mColumns[i], field.asInt());
            break;
        case SHORT:
            values.put(mColumns[i], (short) field.asInt());
            break;
        case LONG:
            values.put(mColumns[i], field.asLong());
            break;
        case FLOAT:
            values.put(mColumns[i], (float) field.asDouble());
            break;
        case DOUBLE:
            values.put(mColumns[i], field.asDouble());
            break;
        case STRING:
            values.put(mColumns[i], field.asText());
            break;
        case BYTE_ARRAY:
            values.put(mColumns[i], Base64.decode(field.asText(), Base64.DEFAULT));
            break;
        case DATE:
            values.put(mColumns[i], mDateFormat.parse(field.asText()).getTime());
            break;
        case BOOLEAN:
            values.put(mColumns[i], field.asBoolean() ? 1 : 0);
            break;
        }
    }
    return values;
}

From source file:com.triarc.sync.SyncAdapter.java

private void addContentValueFor(ContentValues values, JsonObject entity, SyncField syncField)
        throws JSONException, ParseException {
    String name = syncField.getName();
    String dbFieldName = FIELD_PREFIX + name;
    if (!entity.has(name) || entity.get(name).isJsonNull()) {
        values.putNull(dbFieldName);
        return;//from   w w  w .ja v  a  2 s.c om
    }
    switch (syncField.getFieldType()) {
    case Boolean:
        values.put(dbFieldName, entity.get(name).getAsBoolean());
        break;
    case Date:
        Date date = format.parse(entity.get(name).getAsString());
        values.put(dbFieldName, date.getTime());
        break;
    case Numeric:
        values.put(dbFieldName, entity.get(name).getAsLong());
        break;
    case JsonArray:
        JsonArray jsonArray = entity.get(name).getAsJsonArray();
        values.put(dbFieldName, jsonArray.toString());
        break;
    case JsonObject:
        JsonObject object = entity.get(name).getAsJsonObject();
        values.put(dbFieldName, object.toString());
        break;
    case Text:
        values.put(dbFieldName, entity.get(name).getAsString());
        break;
    default:
    }
}

From source file:export.UploadManager.java

void resetDB(final Callback callback, final Uploader uploader, final boolean clearUploads) {
    final String args[] = { Long.toString(uploader.getId()) };
    ContentValues config = new ContentValues();
    config.putNull(Constants.DB.ACCOUNT.AUTH_CONFIG);
    mDB.update(Constants.DB.ACCOUNT.TABLE, config, "_id = ?", args);

    if (clearUploads) {
        mDB.delete(Constants.DB.EXPORT.TABLE, Constants.DB.EXPORT.ACCOUNT + " = ?", args);
    }/* w  w w  . ja v  a  2  s  .com*/

    uploader.reset();
    callback.run(uploader.getName(), Uploader.Status.OK);
}

From source file:org.runnerup.export.UploadManager.java

void resetDB(final Callback callback, final Uploader uploader, final boolean clearUploads) {
    final String args[] = { Long.toString(uploader.getId()) };
    ContentValues config = new ContentValues();
    config.putNull(DB.ACCOUNT.AUTH_CONFIG);
    mDB.update(DB.ACCOUNT.TABLE, config, "_id = ?", args);

    if (clearUploads) {
        mDB.delete(DB.EXPORT.TABLE, DB.EXPORT.ACCOUNT + " = ?", args);
    }//www.  j a v  a2  s.  co m

    uploader.reset();
    callback.run(uploader.getName(), Uploader.Status.OK);
}

From source file:com.viktorrudometkin.burramys.fragment.EditFeedsListFragment.java

private void moveItem(boolean fromIsGroup, boolean toIsGroup, boolean fromIsFeedWithoutGroup, long packedPosTo,
        int packedGroupPosTo, int flatPosFrom) {
    ContentValues values = new ContentValues();
    ContentResolver cr = getActivity().getContentResolver();

    if (fromIsGroup && toIsGroup) {
        values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1);
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
    } else if (!fromIsGroup && toIsGroup) {
        values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1);
        values.putNull(FeedColumns.GROUP_ID);
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
    } else if ((!fromIsGroup && !toIsGroup) || (fromIsFeedWithoutGroup && !toIsGroup)) {
        int groupPrio = ExpandableListView.getPackedPositionChild(packedPosTo) + 1;
        values.put(FeedColumns.PRIORITY, groupPrio);

        int flatGroupPosTo = mListView
                .getFlatListPosition(ExpandableListView.getPackedPositionForGroup(packedGroupPosTo));
        values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatGroupPosTo));
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
    }/*w ww  . ja  v a 2 s .  c  o m*/
}

From source file:org.sufficientlysecure.keychain.provider.KeyWritableRepository.java

public void resetAllLastUpdatedTimes() {
    ContentValues values = new ContentValues();
    values.putNull(UpdatedKeys.LAST_UPDATED);
    values.putNull(UpdatedKeys.SEEN_ON_KEYSERVERS);
    mContentResolver.update(UpdatedKeys.CONTENT_URI, values, null, null);
}

From source file:co.nerdart.ourss.fragment.FeedsListFragment.java

private void moveItem(boolean fromIsGroup, boolean toIsGroup, boolean fromIsFeedWithoutGroup, long packedPosTo,
        int packedGroupPosTo, int flatPosFrom) {
    ContentValues values = new ContentValues();
    ContentResolver cr = getActivity().getContentResolver();

    if (fromIsGroup && toIsGroup) {
        values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1);
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
        cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);

    } else if (!fromIsGroup && toIsGroup) {
        values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1);
        values.putNull(FeedColumns.GROUP_ID);
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
        cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);

    } else if ((!fromIsGroup && !toIsGroup) || (fromIsFeedWithoutGroup && !toIsGroup)) {
        int groupPrio = ExpandableListView.getPackedPositionChild(packedPosTo) + 1;
        values.put(FeedColumns.PRIORITY, groupPrio);

        int flatGroupPosTo = mListView
                .getFlatListPosition(ExpandableListView.getPackedPositionForGroup(packedGroupPosTo));
        values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatGroupPosTo));
        cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null);
        cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);
    }//from  w ww.  j  a  v  a2s.c o m
}