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


Java ContentValues.keySet方法代码示例

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


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

示例1: getCorrectValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**获取正确的的ContentValues,防止数据库操作出错
 * @param values
 * @return
 */
public ContentValues getCorrectValues(ContentValues values) {
	if (values == null || values.size() <= 0) {
		return null;
	}

	//去除所有空key
	Set<String> set = values.keySet();
	for (String key : set) {
		if (StringUtil.isNotEmpty(key, true) == false) {
			values.remove(key);
		}
	}

	return values;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:SQLHelper.java

示例2: setupRequestBody

import android.content.ContentValues; //导入方法依赖的package包/类
private  static RequestBody setupRequestBody(ContentValues values){
    RequestBody requestBody=null;
    if (values != null && values.size() > 0) {
        FormBody.Builder formEncoding = new FormBody.Builder();

        Set<String> keySet = values.keySet();
        for (String key : keySet) {
            try {
                values.getAsString(key);
                formEncoding.add(key, values.getAsString(key));

            } catch (Exception ex) {

                Log.d("GonnectLog","Error Happend While Setting Up Request Body : "+ex.getMessage());
            }
        }
        requestBody = formEncoding.build();

    }
    return requestBody;
}
 
开发者ID:poorya-abbasi,项目名称:Gonnect,代码行数:22,代码来源:Gonnect.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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


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