ContentValues args = new ContentValues(); args.putNull(KEY_RISK_AMOUNT);
@Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { ContentValues cv = new ContentValues(); cv.put("deleted", 1); cv.put("empty", 1); cv.putNull("subject"); cv.putNull("sender_list"); cv.putNull("date"); cv.putNull("to_list"); cv.putNull("cc_list"); cv.putNull("bcc_list"); cv.putNull("preview"); cv.putNull("reply_to_list"); cv.putNull("message_part_id"); db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); } catch (MessagingException e) { throw new WrappedException(e); } getFolder().deleteFulltextIndexEntry(db, databaseId); return null; } });
@NonNull @Override public Object emptyColumn(@NonNull final String column) { checkState(!compiled, ERROR_MESSAGE); contentValues.putNull(checkNotNull(column)); return this; }
/** * Calling {@link android.database.sqlite.SQLiteDatabase#insert(String, String, android.content.ContentValues)} to * persist the current model. * * @param baseObj * Current model to persist. * @param values * To store data of current model for persisting. * @return The row ID of the newly inserted row, or -1 if an error occurred. */ private long saving(LitePalSupport baseObj, ContentValues values) { if (values.size() == 0) { values.putNull("id"); } return mDatabase.insert(baseObj.getTableName(), null, values); }
@Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, MessagingException { ContentValues cv = new ContentValues(); cv.putNull("message_part_id"); db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); } catch (MessagingException e) { throw new WrappedException(e); } setFlag(Flag.X_DOWNLOADED_FULL, false); setFlag(Flag.X_DOWNLOADED_PARTIAL, false); return null; } });
values.remove(key); if (object == null) { values.putNull(convertedKey); } else { String className = object.getClass().getName();
/** * When the associations breaks between current model and associated models, * clear all the associated models' foreign key value if it exists. * * @param baseObj * Current model that is persisted. */ private void clearFKValueInAssociatedTable(LitePalSupport baseObj) { List<String> associatedTableNames = baseObj.getListToClearAssociatedFK(); for (String associatedTableName : associatedTableNames) { String fkColumnName = getForeignKeyColumnName(baseObj.getTableName()); ContentValues values = new ContentValues(); values.putNull(fkColumnName); String whereClause = fkColumnName + " = " + baseObj.getBaseObjId(); mDatabase.update(associatedTableName, values, whereClause, null); } }
@Test public void shouldCorrectlyReturnNullValues() { database.execSQL("CREATE TABLE null_test (col_int INTEGER, col_text TEXT, col_real REAL, col_blob BLOB)"); ContentValues data = new ContentValues(); data.putNull("col_int"); data.putNull("col_text"); data.putNull("col_real"); data.putNull("col_blob"); assertThat(database.insert("null_test", null, data)).isAtLeast(0L); Cursor nullValuesCursor = database.query("null_test", null, null, null, null, null, null); nullValuesCursor.moveToFirst(); final int colsCount = 4; for (int i = 0; i < colsCount; i++) { assertThat(nullValuesCursor.getType(i)).isEqualTo(Cursor.FIELD_TYPE_NULL); assertThat(nullValuesCursor.getString(i)).isNull(); } assertThat(nullValuesCursor.getBlob(3)).isNull(); }
/** * Before updating model, it will be analyzed first. Put all the data * contained by the model into ContentValues, including the fields value and * foreign key value. If the associations between models has been removed. * The foreign key value in database should be cleared too. * * @param baseObj * Current model to update. * @param supportedFields * List of all supported fields. * @param values * To store data of current model for updating. * @throws java.lang.reflect.InvocationTargetException * @throws IllegalAccessException * @throws NoSuchMethodException * @throws IllegalArgumentException * @throws SecurityException */ private void beforeUpdate(LitePalSupport baseObj, List<Field> supportedFields, ContentValues values) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { putFieldsValue(baseObj, supportedFields, values); putForeignKeyValue(values, baseObj); for (String fkName : baseObj.getListToClearSelfFK()) { values.putNull(fkName); } }
@Test public void testUpdateAllRowsWithStaticUpdate() { int allRows = getRowsCount(studentTable); ContentValues values = new ContentValues(); values.put("name", "Zuckerburg"); int affectedRows = LitePal.updateAll(Student.class, values); assertEquals(allRows, affectedRows); String table = DBUtility.getIntermediateTableName(studentTable, DBUtility.getTableNameByClassName(Teacher.class.getName())); allRows = getRowsCount(table); values.clear(); values.putNull(studentTable + "_id"); affectedRows = LitePal.updateAll(table, values); assertEquals(allRows, affectedRows); }
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);
testValues.putNull(columnName);