Java Code Examples for android.content.ContentValues#keySet()
The following examples show how to use
android.content.ContentValues#keySet() .
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: Session.java From Android-ORM with Apache License 2.0 | 6 votes |
/** * Update from database with criteria. * * @param criteria * the criteria query instance. * @param values * new values to update. The key of ContentValues is java * property name, if the criteria has an alias, the key must add * a $Alias. prefix. * @return the number of rows affected */ public int update(Criteria criteria, ContentValues values) { String sql = criteria.toSQL(); String table = Mapping.getInstance() .getTableName(criteria.getRoot().getClazz()); String where = criteria.getWhere(); String[] args = criteria.getStringArgs(); ContentValues colValues = new ContentValues(values.size()); for (String key : values.keySet()) { Row.putColumnValues(colValues, criteria.property2Column(key), values.get(key)); } if (Aorm.isDebug()) { log("update " + table + " values: " + colValues + ", where = " + where + ", args = " + criteria.getArgs()); } int count = update(table, colValues, where, args); notifySessionListener(criteria.getRoot().getClazz()); return count; }
Example 2
Source File: FDroidProvider.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
protected void validateFields(String[] validFields, ContentValues values) throws IllegalArgumentException { for (final String key : values.keySet()) { boolean isValid = false; for (final String validKey : validFields) { if (validKey.equals(key)) { isValid = true; break; } } if (!isValid) { throw new IllegalArgumentException( "Cannot save field '" + key + "' to provider " + getProviderName()); } } }
Example 3
Source File: BaseModelProvider.java From hr with GNU Affero General Public License v3.0 | 6 votes |
private ContentValues[] generateValues(ContentValues values) { OValues data_value = new OValues(); OValues rel_value = new OValues(); for (String key : values.keySet()) { OColumn column = mModel.getColumn(key); if (column != null) { if (column.getRelationType() == null) { data_value.put(key, values.get(key)); } else { if (column.getRelationType() == OColumn.RelationType.ManyToOne) { data_value.put(key, values.get(key)); } else { rel_value.put(key, values.get(key).toString()); } } } } return new ContentValues[]{data_value.toContentValues(), rel_value.toContentValues()}; }
Example 4
Source File: BaseModelProvider.java From hr with GNU Affero General Public License v3.0 | 5 votes |
private void storeUpdateRelationRecords(ContentValues values, String selection, String[] args) { int row_id = mModel.selectRowId(selection, args); for (String key : values.keySet()) { try { mModel.storeManyToManyRecord(key, row_id, OdooRecordUtils.<Integer>toList(values.getAsString(key)), OModel.Command.Replace); } catch (InvalidObjectException e) { e.printStackTrace(); } } }
Example 5
Source File: CatnutUtils.java From catnut with MIT License | 5 votes |
/** * 更新sql */ public static String update(ContentValues values, String from, String where) { StringBuilder sb = new StringBuilder("UPDATE ").append(from).append(" SET"); for (String key : values.keySet()) { sb.append(" ").append(key).append("=").append(reflectString(values.get(key))).append(","); } sb.deleteCharAt(sb.length() - 1); // remove the last ',' if (where != null) { sb.append(" WHERE ").append(where); } return sb.toString(); }
Example 6
Source File: BaseModelProvider.java From framework with GNU Affero General Public License v3.0 | 5 votes |
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 7
Source File: BaseModelProvider.java From framework with GNU Affero General Public License v3.0 | 5 votes |
private void storeUpdateRelationRecords(OModel model, ContentValues values, String selection, String[] args) { int row_id = model.selectRowId(selection, args); for (String key : values.keySet()) { try { OColumn column = model.getColumn(key); RelValues relValues = (RelValues) OObjectUtils.byteToObject( (byte[]) values.get(key)); model.handleRelationValues(row_id, column, relValues); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } }
Example 8
Source File: OValues.java From framework with GNU Affero General Public License v3.0 | 5 votes |
public static OValues from(ContentValues contentValues) { OValues values = new OValues(); for (String key : contentValues.keySet()) { values.put(key, contentValues.get(key)); } return values; }
Example 9
Source File: TaskDb.java From SyncManagerAndroid-DemoGoogleTasks with MIT License | 5 votes |
static private long createTask(SQLiteDatabase db, Task task) { ContentValues initialValues = contentValuesFromTask(task, false); long result = db.insert(TASK_TABLE_NAME, null, initialValues); Log.d(TAG, "createTask result:"+result); for(String key : initialValues.keySet()) { Log.d(TAG, "key:"+key); if (key.equals(TASK_FIELD_NAME_SERVER_ID)) { Log.d(TAG, "serverid: "+initialValues.getAsString(key)); } } return result; }
Example 10
Source File: ItemsContentProvider.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
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 11
Source File: OValues.java From hr with GNU Affero General Public License v3.0 | 5 votes |
public static OValues from(ContentValues contentValues) { OValues values = new OValues(); for (String key : contentValues.keySet()) { values.put(key, contentValues.get(key)); } return values; }
Example 12
Source File: QuantumFluxContentProvider.java From QuantumFlux with Apache License 2.0 | 5 votes |
private boolean shouldChangesBeNotified(TableDetails tableDetails, ContentValues contentValues) { boolean notify = false; for (String columnName : contentValues.keySet()) { TableDetails.ColumnDetails column = tableDetails.findColumn(columnName); if (column != null) { notify = notify || column.notifyChanges(); } } return notify; }
Example 13
Source File: DatabaseImport.java From financisto with GNU General Public License v2.0 | 5 votes |
private void removeUnknownColumns(ContentValues values, String[] columnNames, String tableName) { Set<String> possibleKeys = new HashSet<>(Arrays.asList(columnNames)); Set<String> keys = new HashSet<>(values.keySet()); for (String key : keys) { if (!possibleKeys.contains(key)) { values.remove(key); Log.i("Financisto", "Removing "+key+" from backup values for "+tableName); } } }
Example 14
Source File: SQLiteDatabase.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * 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('('); Object[] bindArgs = null; int size = (initialValues != null && !initialValues.isEmpty()) ? initialValues.size() : 0; if (size > 0) { 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(')'); sql.append(" VALUES ("); for (i = 0; i < size; i++) { sql.append((i > 0) ? ",?" : "?"); } } else { sql.append(nullColumnHack + ") VALUES (NULL"); } sql.append(')'); SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs); try { return statement.executeInsert(); } finally { statement.close(); } } finally { releaseReference(); } }
Example 15
Source File: SQLiteDatabase.java From squidb with Apache License 2.0 | 4 votes |
/** * 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); } SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs); try { return statement.executeUpdateDelete(); } finally { statement.close(); } } finally { releaseReference(); } }
Example 16
Source File: SQLiteDatabase.java From squidb with Apache License 2.0 | 4 votes |
/** * 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 the primary key of the existing row if the input param 'conflictAlgorithm' = * {@link #CONFLICT_IGNORE} * OR -1 if any error */ 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('('); Object[] bindArgs = null; int size = (initialValues != null && initialValues.size() > 0) ? initialValues.size() : 0; if (size > 0) { 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(')'); sql.append(" VALUES ("); for (i = 0; i < size; i++) { sql.append((i > 0) ? ",?" : "?"); } } else { sql.append(nullColumnHack + ") VALUES (NULL"); } sql.append(')'); SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs); try { return statement.executeInsert(); } finally { statement.close(); } } finally { releaseReference(); } }
Example 17
Source File: Database.java From kripton with Apache License 2.0 | 4 votes |
/** * {@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 18
Source File: Database.java From cwac-saferoom with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @SuppressWarnings("ThrowFromFinallyBlock") @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: SQLiteDatabase.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * 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.isEmpty()) { 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(); } }
Example 20
Source File: CPOrmContentProvider.java From CPOrm with MIT License | 3 votes |
private boolean shouldChangesBeNotified(TableDetails tableDetails, ContentValues contentValues) { boolean notify = false; for (String columnName : contentValues.keySet()) { TableDetails.ColumnDetails column = tableDetails.findColumn(columnName); if (column != null) notify = notify || column.notifyChanges(); } return notify; }