本文整理匯總了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 += "}";
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}