Java Code Examples for android.content.ContentValues#get()

The following examples show how to use android.content.ContentValues#get() . 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: TaskProvider.java    From opentasks-provider with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the given category values.
 * 
 * @param values
 *            The category properties to validate.
 * @throws IllegalArgumentException
 *             if any of the values is invalid.
 */
private void validateCategoryValues(ContentValues values, boolean isNew, boolean isSyncAdapter)
{
	// row id can not be changed or set manually
	if (values.containsKey(Categories._ID))
	{
		throw new IllegalArgumentException("_ID can not be set manually");
	}

	if (isNew != values.containsKey(Categories.ACCOUNT_NAME) && (!isNew || values.get(Categories.ACCOUNT_NAME) != null))
	{
		throw new IllegalArgumentException("ACCOUNT_NAME is write-once and required on INSERT");
	}

	if (isNew != values.containsKey(Categories.ACCOUNT_TYPE) && (!isNew || values.get(Categories.ACCOUNT_TYPE) != null))
	{
		throw new IllegalArgumentException("ACCOUNT_TYPE is write-once and required on INSERT");
	}
}
 
Example 2
Source File: TaskProvider.java    From opentasks with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the given category values.
 *
 * @param values
 *         The category properties to validate.
 *
 * @throws IllegalArgumentException
 *         if any of the values is invalid.
 */
private void validateCategoryValues(ContentValues values, boolean isNew, boolean isSyncAdapter)
{
    // row id can not be changed or set manually
    if (values.containsKey(Categories._ID))
    {
        throw new IllegalArgumentException("_ID can not be set manually");
    }

    if (isNew != values.containsKey(Categories.ACCOUNT_NAME) && (!isNew || values.get(Categories.ACCOUNT_NAME) != null))
    {
        throw new IllegalArgumentException("ACCOUNT_NAME is write-once and required on INSERT");
    }

    if (isNew != values.containsKey(Categories.ACCOUNT_TYPE) && (!isNew || values.get(Categories.ACCOUNT_TYPE) != null))
    {
        throw new IllegalArgumentException("ACCOUNT_TYPE is write-once and required on INSERT");
    }
}
 
Example 3
Source File: AccountDb.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
private boolean insertNewAccount(ContentValues values) {
  Preconditions.checkNotNull(values);
  Preconditions.checkNotNull(values.get(NAME_COLUMN));
  AccountIndex index =
      new AccountIndex((String) values.get(NAME_COLUMN), (String) values.get(ISSUER_COLUMN));
  if (indexExists(index)) {
    return false;  // An account with this name already exists
  }
  return mDatabase.insert(TABLE_NAME, null, values) != -1;
}
 
Example 4
Source File: ItemsContentProvider.java    From android-galaxyzoo with GNU General Public License v3.0 5 votes vote down vote up
private static ContentValues getMappedContentValues(final ContentValues values, final Map<String, String> projectionMap) {
    final ContentValues result = new ContentValues();

    for (final String keyExternal : values.keySet()) {
        final String keyInternal = projectionMap.get(keyExternal);
        if (!TextUtils.isEmpty(keyInternal)) {
            final Object value = values.get(keyExternal);
            putValueInContentValues(result, keyInternal, value);
        }
    }

    return result;
}
 
Example 5
Source File: RecipeContentProvider.java    From search-samples with Apache License 2.0 5 votes vote down vote up
public Uri insertNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "INSERT INTO `" + RecipeNoteTable.TABLE + "` (`" + RecipeNoteTable
            .RECIPE_ID_COLUMN + "`, `" + RecipeNoteTable.TEXT_COLUMN + "`) VALUES ('" + uri
            .getLastPathSegment() + "', '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "')";
    database.getWritableDatabase().execSQL(sql);
    return uri;
}
 
Example 6
Source File: RecipeContentProvider.java    From app-indexing with Apache License 2.0 5 votes vote down vote up
public int updateNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "UPDATE `" + RecipeNoteTable.TABLE + "` SET `" + RecipeNoteTable.TEXT_COLUMN
            + "` = '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "' where `" +
            RecipeNoteTable.RECIPE_ID_COLUMN + "` = '" + uri.getLastPathSegment() + "'";
    database.getWritableDatabase().execSQL(sql);
    return 1;
}
 
Example 7
Source File: RecipeContentProvider.java    From app-indexing with Apache License 2.0 5 votes vote down vote up
public int updateNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "UPDATE `" + RecipeNoteTable.TABLE + "` SET `" + RecipeNoteTable.TEXT_COLUMN
            + "` = '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "' where `" +
            RecipeNoteTable.RECIPE_ID_COLUMN + "` = '" + uri.getLastPathSegment() + "'";
    database.getWritableDatabase().execSQL(sql);
    return 1;
}
 
Example 8
Source File: Insert.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
@NonNull
public Insert<TModel> columnValues(@NonNull ContentValues contentValues) {
    java.util.Set<Map.Entry<String, Object>> entries = contentValues.valueSet();
    int count = 0;
    String[] columns = new String[contentValues.size()];
    Object[] values = new Object[contentValues.size()];
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        columns[count] = key;
        values[count] = contentValues.get(key);
        count++;
    }

    return columns(columns).values(values);
}
 
Example 9
Source File: TimeCatContentProvider.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
    String[] path= uri.getPath().split(SEPARATOR);
    String type=path[1];
    String key=path[2];
    Object obj= (Object) values.get(VALUE);
    if (obj!=null)
        SPHelperImpl.save(getContext(),key,obj);
    return null;
}
 
Example 10
Source File: RepoProvider.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {

    // Don't let people specify arbitrary priorities. Instead, we are responsible
    // for making sure that newly created repositories by default have the highest priority.
    values.put(Cols.PRIORITY, getMaxPriority() + 1);

    if (!values.containsKey(Cols.ADDRESS)) {
        throw new UnsupportedOperationException("Cannot add repo without an address.");
    }

    // The following fields have NOT NULL constraints in the DB, so need
    // to be present.

    if (!values.containsKey(Cols.IN_USE)) {
        values.put(Cols.IN_USE, 1);
    }

    if (!values.containsKey(Cols.MAX_AGE)) {
        values.put(Cols.MAX_AGE, 0);
    }

    if (!values.containsKey(Cols.VERSION)) {
        values.put(Cols.VERSION, 0);
    }

    if (!values.containsKey(Cols.NAME) || values.get(Cols.NAME) == null) {
        final String address = values.getAsString(Cols.ADDRESS);
        values.put(Cols.NAME, Repo.addressToName(address));
    }

    long id = db().insertOrThrow(getTableName(), null, values);
    Utils.debugLog(TAG, "Inserted repo. Notifying provider change: '" + uri + "'.");
    getContext().getContentResolver().notifyChange(uri, null);
    return getContentUri(id);
}
 
Example 11
Source File: BaseModelProvider.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
private ContentValues[] generateValues(OModel model, ContentValues values) {
    OValues data_value = new OValues();
    OValues rel_value = new OValues();
    for (String key : values.keySet()) {
        OColumn column = model.getColumn(key);
        if (column != null) {
            if (column.getRelationType() == null) {
                data_value.put(key, values.get(key));
            } else {
                if (column.getRelationType() == OColumn.RelationType.ManyToOne) {
                    if (!(values.get(key) instanceof byte[]))
                        data_value.put(key, values.get(key));
                    else {
                        // Creating many to one record and assigning id to record
                        OModel m2oModel = model.createInstance(column.getType());
                        try {
                            OValues m2oVal = (OValues) OObjectUtils.byteToObject(
                                    (byte[]) values.get(key));
                            int id = m2oModel.insert(m2oVal);
                            data_value.put(key, id);
                        } catch (IOException | ClassNotFoundException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    rel_value.put(key, values.get(key));
                }
            }
        }
    }
    return new ContentValues[]{data_value.toContentValues(), rel_value.toContentValues()};
}
 
Example 12
Source File: RecipeContentProvider.java    From search-samples with Apache License 2.0 5 votes vote down vote up
public Uri insertNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "INSERT INTO `" + RecipeNoteTable.TABLE + "` (`" + RecipeNoteTable
            .RECIPE_ID_COLUMN + "`, `" + RecipeNoteTable.TEXT_COLUMN + "`) VALUES ('" + uri
            .getLastPathSegment() + "', '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "')";
    database.getWritableDatabase().execSQL(sql);
    return uri;
}
 
Example 13
Source File: MainActivity.java    From ArscEditor with Apache License 2.0 4 votes vote down vote up
@Override
protected String doInBackground(String... params) {
	switch (ResType) {

	case ARSC:
		for (ContentValues resource : RESOURCES) {
			// 获取资源的键
			String NAME = (String) resource.get(MyObj.NAME);
			// 获取资源的值
			String VALUE = (String) resource.get(MyObj.VALUE);
			// 获取资源类型
			String TYPE = (String) resource.get(MyObj.TYPE);
			// 获取资源分支
			String CONFIG = (String) resource.get(MyObj.CONFIG);

			// 如果资源的Config开头存在-符号,并且Config列表中不存在该资源的Config元素,并且资源种类是params[0]的值
			if (CONFIG.startsWith("-") && !Configs.contains(CONFIG.substring(1)) && TYPE.equals(params[0]))
				// 向Config列表中添加元素
				Configs.add(CONFIG.substring(1));
			// 如果资源的Config开头不存在-符号,并且Config列表中不存在该资源的Config元素,并且资源种类是params[0]的值
			else if (!CONFIG.startsWith("-") && !Configs.contains(CONFIG) && TYPE.equals(params[0]))
				Configs.add(CONFIG);

			// 如果资源的Config开头存在-符号,并且Config列表中存在该资源的Config元素,并且Config是params[1]的值
			if (TYPE.equals(params[0]) && CONFIG.startsWith("-") && CONFIG.substring(1).equals(params[1])) {
				// 向储存字符串的列表中添加字符串成员
				txtOriginal.add(VALUE);
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键的列表添加键
				txtTranslated_Key.add(NAME);
				// 如果资源的Config开头不存在-符号,并且Config列表中存在该资源的Config元素,并且Config是params[1]的值
			} else if (TYPE.equals(params[0]) && !CONFIG.startsWith("-") && CONFIG.equals(params[1])) {
				// 向储存字符串的列表中添加字符串成员
				txtOriginal.add(VALUE);
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键的列表添加键
				txtTranslated_Key.add(NAME);
			}
		}
		break;
	case AXML:
		try {
			mAndRes.mAXMLDecoder.getStrings(txtOriginal);
			for (int i = 0; i < txtOriginal.size(); i++) {
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键添加空成员
				txtTranslated_Key.add("");
			}
		} catch (CharacterCodingException e) {
			return e.toString();
		}
		break;
	case DEX:

		break;
	}
	// 返回一个成功的标志
	return getString(R.string.success);
}
 
Example 14
Source File: MetadataDbHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
Example 15
Source File: MetadataDbHelper.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
Example 16
Source File: UrlFieldAdapter.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
@Override
public URI getFrom(ContentValues values)
{
	return values.get(mFieldName) == null ? null : URI.create(values.getAsString(mFieldName));
}
 
Example 17
Source File: MetadataDbHelper.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
Example 18
Source File: Database.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int update(String table, int conflictAlgorithm, ContentValues values, String whereClause,
		Object[] whereArgs) {
	// taken from SQLiteDatabase class.
	if (values == null || values.size() == 0) {
		throw new IllegalArgumentException("Empty values");
	}
	StringBuilder sql = new StringBuilder(120);
	sql.append("UPDATE ");
	sql.append(CONFLICT_VALUES[conflictAlgorithm]);
	sql.append(table);
	sql.append(" SET ");

	// move all bind args to one array
	int setValuesSize = values.size();
	int bindArgsSize = (whereArgs == null) ? setValuesSize : (setValuesSize + whereArgs.length);
	Object[] bindArgs = new Object[bindArgsSize];
	int i = 0;
	for (String colName : values.keySet()) {
		sql.append((i > 0) ? "," : "");
		sql.append(colName);
		bindArgs[i++] = values.get(colName);
		sql.append("=?");
	}
	if (whereArgs != null) {
		for (i = setValuesSize; i < bindArgsSize; i++) {
			bindArgs[i] = whereArgs[i - setValuesSize];
		}
	}
	if (!TextUtils.isEmpty(whereClause)) {
		sql.append(" WHERE ");
		sql.append(whereClause);
	}
	SupportSQLiteStatement statement = compileStatement(sql.toString());

	try {
		SimpleSQLiteQuery.bind(statement, bindArgs);
		return statement.executeUpdateDelete();
	} finally {
		try {
			statement.close();
		} catch (Exception e) {
			throw new RuntimeException("Exception attempting to close statement", e);
		}
	}
}
 
Example 19
Source File: SimpleFieldAdapter.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
@Override
public boolean existsIn(ContentValues values)
{
	return values.get(fieldName()) != null;
}
 
Example 20
Source File: UrlFieldAdapter.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
public URI getFrom(ContentValues values)
{
    return values.get(mFieldName) == null ? null : URI.create(values.getAsString(mFieldName));
}