Joblogs——ContentValues的使用
2015-09-28 14:57
447 查看
ContentValues在Android的SQLiteDatabase.update (String table, ContentValues values, String whereClause, String[] whereArgs)中以参数的形式使用。
至于ContentValues的具体使用。查看SQLiteDatabase.update 方法源码:
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);
}
SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs);
try {
return statement.executeUpdateDelete();
} finally {
statement.close();
}
} finally {
releaseReference();
}
}
ContentValues,使用Has和Map来保存数据,同时还可以序列化:
public final class ContentValues implements Parcelable {
public static final String TAG = "ContentValues";
/** Holds the actual values */
private HashMap<String, Object> mValues;
…
至于ContentValues的具体使用。查看SQLiteDatabase.update 方法源码:
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);
}
SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs);
try {
return statement.executeUpdateDelete();
} finally {
statement.close();
}
} finally {
releaseReference();
}
}
ContentValues,使用Has和Map来保存数据,同时还可以序列化:
public final class ContentValues implements Parcelable {
public static final String TAG = "ContentValues";
/** Holds the actual values */
private HashMap<String, Object> mValues;
…
相关文章推荐
- UISwitch开关控件属性介绍以及获取开关状态并做出响应
- Android UI开发
- Leetcode82: Unique Binary Search Trees
- 关于UIBezierPath的使用
- EasyUI 格式化列
- 在非Activity(非主线程)中更新UI的办法:(一)Handler+Thread+Activity静态成员变量
- Xcode 7 UI 测试初窥
- break ,continue ,return的区别
- SoapUI中XML解析
- Json转换利器Gson-Gson注解和GsonBuilder
- Android UI - 实现广告Banner轮播效果
- Groovy Script in SoapUI REST Testing
- UI Overview
- UML之时序图(Sequence Diagram)
- 进度条 UIProgressView
- iOS开发UI篇—iOS开发中三种简单的动画设置
- 最简单的推送--uexGetui
- iOS UI进阶-1.1 Quartz2D 图片水印/裁剪/截图
- IDEA Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executin
- hashtable ,hashmap的containsValue与containsKey