当前位置: 首页>>代码示例>>Java>>正文


Java ContentValues.get方法代码示例

本文整理汇总了Java中android.content.ContentValues.get方法的典型用法代码示例。如果您正苦于以下问题:Java ContentValues.get方法的具体用法?Java ContentValues.get怎么用?Java ContentValues.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.ContentValues的用法示例。


在下文中一共展示了ContentValues.get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getString

import android.content.ContentValues; //导入方法依赖的package包/类
private String getString(ContentValues values) {
	if (values == null || values.size() <= 0) {
		return "";
	}

	String s = "{\n";
	for (String key : values.keySet()) {
		s += ("    " + key + ":" + values.get(key) + ",\n");
	}
	return s += "}";
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:DemoSQLActivity.java

示例2: update

import android.content.ContentValues; //导入方法依赖的package包/类
@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 (!isEmpty(whereClause)) {
        sql.append(" WHERE ");
        sql.append(whereClause);
    }
    SupportSQLiteStatement stmt = compileStatement(sql.toString());
    SimpleSQLiteQuery.bind(stmt, bindArgs);
    return stmt.executeUpdateDelete();
}
 
开发者ID:albertogiunta,项目名称:justintrain-client-android,代码行数:38,代码来源:FrameworkSQLiteDatabase.java

示例3: enforceAllowedValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Remove column from values, and throw a SecurityException if the value isn't within the
 * specified allowedValues.
 */
private void enforceAllowedValues(ContentValues values, String column,
                                  Object... allowedValues) {
    Object value = values.get(column);
    values.remove(column);
    for (Object allowedValue : allowedValues) {
        if (value == null && allowedValue == null) {
            return;
        }
        if (value != null && value.equals(allowedValue)) {
            return;
        }
    }
    throw new SecurityException("Invalid value for " + column + ": " + value);
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:19,代码来源:DownloadProvider.java

示例4: insert

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public Uri insert(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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:37,代码来源:RepoProvider.java

示例5: insert

import android.content.ContentValues; //导入方法依赖的package包/类
@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(key,obj);
    return null;
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:12,代码来源:BigBangContentProvider.java

示例6: enforceAllowedValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Remove column from values, and throw a SecurityException if the value isn't within the
 * specified allowedValues.
 */
private void enforceAllowedValues(ContentValues values, String column,
        Object... allowedValues) {
    Object value = values.get(column);
    values.remove(column);
    for (Object allowedValue : allowedValues) {
        if (value == null && allowedValue == null) {
            return;
        }
        if (value != null && value.equals(allowedValue)) {
            return;
        }
    }
    throw new SecurityException("Invalid value for " + column + ": " + value);
}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:19,代码来源:DownloadProvider.java

示例7: matchesSafely

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(ContentValues values, Description mismatchDescription)
{
    if (values.get(mExpectedKey) != null)
    {
        mismatchDescription.appendText(String.format("value of key \"%s\" was \"%s\"", mExpectedKey, values.get(mExpectedKey)));
        return false;
    }
    return true;
}
 
开发者ID:dmfs,项目名称:ContentPal,代码行数:11,代码来源:NullValue.java

示例8: update

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * {@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 (!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);
    }
  }
}
 
开发者ID:commonsguy,项目名称:cwac-saferoom,代码行数:52,代码来源:Database.java

示例9: doInBackground

import android.content.ContentValues; //导入方法依赖的package包/类
@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);
}
 
开发者ID:seaase,项目名称:ArscEditor,代码行数:63,代码来源:MainActivity.java

示例10: insertWithOnConflict

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * General method for inserting a row into the database.
 *
 * @param table             the table to insert the row into
 * @param nullColumnHack    optional; may be <code>null</code>.
 *                          SQL doesn't allow inserting a completely empty row without
 *                          naming at least one column name.  If your provided <code>initialValues</code> is
 *                          empty, no column names are known and an empty row can't be inserted.
 *                          If not set to null, the <code>nullColumnHack</code> parameter
 *                          provides the name of nullable column name to explicitly insert a NULL into
 *                          in the case where your <code>initialValues</code> is empty.
 * @param initialValues     this map contains the initial column values for the
 *                          row. The keys should be the column names and the values the
 *                          column values
 * @param conflictAlgorithm for insert conflict resolver
 * @return the row ID of the newly inserted row OR <code>-1</code> if either the
 * input parameter <code>conflictAlgorithm</code> = {@link #CONFLICT_IGNORE}
 * or an error occurred.
 */
public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm) {
    acquireReference();
    try {
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT");
        sql.append(CONFLICT_VALUES[conflictAlgorithm]);
        sql.append(" INTO ");
        sql.append(table);
        sql.append('(');

        int size = (initialValues != null && initialValues.size() > 0) ? initialValues.size() : 0;

        if (size > 0) {
            Object[] bindArgs = new Object[size];
            int      i        = 0;
            for (String colName : initialValues.keySet()) {
                sql.append((i > 0) ? "," : "");
                sql.append(colName);
                bindArgs[i++] = initialValues.get(colName);
            }
            sql.append(')');

            // 拼接VALUES语句
            {
                StringBuilder valuesSql = new StringBuilder();

                valuesSql.append(" VALUES (");
                for (i = 0; i < size; i++) {
                    valuesSql.append((i > 0) ? ",?" : "?");
                }
                valuesSql.append(')');

                String valuesStr = KbSqlBuilder.bindArgs(valuesSql.toString(), bindArgs);

                sql.append(valuesStr);
            }
        } else {
            sql.append(nullColumnHack + ") VALUES (NULL");
            sql.append(')');
        }

        // 执行语句
        execSQL(sql.toString());

        return 0;
    } finally {
        releaseReference();
    }
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:69,代码来源:ShadowSQLiteDatabase.java

示例11: updateWithOnConflict

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Convenience method for updating rows in the database.
 *
 * @param table             the table to update in
 * @param values            a map from column names to new column values. null is a
 *                          valid value that will be translated to NULL.
 * @param whereClause       the optional WHERE clause to apply when updating.
 *                          Passing null will update all rows.
 * @param whereArgs         You may include ?s in the where clause, which
 *                          will be replaced by the values from whereArgs. The values
 *                          will be bound as Strings.
 * @param conflictAlgorithm for update conflict resolver
 * @return the number of rows affected
 */
public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) {
    if (values == null || values.size() == 0) {
        throw new IllegalArgumentException("Empty values");
    }

    acquireReference();
    try {
        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);
        }

        String afterSql = KbSqlBuilder.bindArgs(sql.toString(), bindArgs);

        try {
            Statement statement = mConnection.createStatement();
            int       rowCount  = statement.executeUpdate(afterSql.toString());

            if (!isTransaction) {
                mConnection.commit();
            }
            return rowCount;
        } catch (java.sql.SQLException e) {
            throw new SQLException("", e);
        }
    } finally {
        releaseReference();
    }
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:66,代码来源:ShadowSQLiteDatabase.java

示例12: insertWithOnConflict

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * General method for inserting a row into the database.
 *
 * @param table             the table to insert the row into
 * @param nullColumnHack    optional; may be <code>null</code>.
 *                          SQL doesn't allow inserting a completely empty row without
 *                          naming at least one column name.  If your provided <code>initialValues</code> is
 *                          empty, no column names are known and an empty row can't be inserted.
 *                          If not set to null, the <code>nullColumnHack</code> parameter
 *                          provides the name of nullable column name to explicitly insert a NULL into
 *                          in the case where your <code>initialValues</code> is empty.
 * @param initialValues     this map contains the initial column values for the
 *                          row. The keys should be the column names and the values the
 *                          column values
 * @param conflictAlgorithm for insert conflict resolver
 * @return the row ID of the newly inserted row OR <code>-1</code> if either the
 * input parameter <code>conflictAlgorithm</code> = {@link #CONFLICT_IGNORE}
 * or an error occurred.
 */
public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm) {
    acquireReference();
    try {
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT");
        sql.append(CONFLICT_VALUES[conflictAlgorithm]);
        sql.append(" INTO ");
        sql.append(table);
        sql.append('(');

        int size = (initialValues != null && initialValues.size() > 0) ? initialValues.size() : 0;

        if (size > 0) {
            Object[] bindArgs = new Object[size];
            int      i        = 0;
            for (String colName : initialValues.keySet()) {
                sql.append((i > 0) ? "," : "");
                sql.append(colName);
                bindArgs[i++] = initialValues.get(colName);
            }
            sql.append(')');

            // 替换boolean类型为int
            bindArgs = KbSqlParser.replaceBoolean(bindArgs);

            // 拼接VALUES语句
            {
                StringBuilder valuesSql = new StringBuilder();

                valuesSql.append(" VALUES (");
                for (i = 0; i < size; i++) {
                    valuesSql.append((i > 0) ? ",?" : "?");
                }
                valuesSql.append(')');

                String valuesStr = KbSqlBuilder.bindArgs(valuesSql.toString(), bindArgs);

                sql.append(valuesStr);
            }
        } else {
            sql.append(nullColumnHack + ") VALUES (NULL");
            sql.append(')');
        }

        // 执行语句
        execSQL(sql.toString());

        return 0;
    } finally {
        releaseReference();
    }
}
 
开发者ID:kkmike999,项目名称:KBUnitTest,代码行数:72,代码来源:ShadowSQLiteDatabase.java

示例13: completeWithDefaultValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:46,代码来源:MetadataDbHelper.java


注:本文中的android.content.ContentValues.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。