本文整理汇总了Java中android.content.ContentValues.putNull方法的典型用法代码示例。如果您正苦于以下问题:Java ContentValues.putNull方法的具体用法?Java ContentValues.putNull怎么用?Java ContentValues.putNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentValues
的用法示例。
在下文中一共展示了ContentValues.putNull方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateName
import android.content.ContentValues; //导入方法依赖的package包/类
@OnClick(R.id.btUpdate)
public void updateName(){
ContentValues contentValues = new ContentValues();
if (mCheckBoxNull.isChecked()) {
contentValues.put("NAME", (String)null);
} else {
contentValues.put("NAME", mETName.getEditableText().toString());
}
contentValues.putNull("SEND_TIME");
mDB.update("category", contentValues, "_id = ? ", new String[] {Long.toString(mId)});
finish();
}
示例2: getCV
import android.content.ContentValues; //导入方法依赖的package包/类
public static ContentValues getCV(@NonNull VKApiPhotoAlbum p){
ContentValues cv = new ContentValues();
cv.put(ALBUM_ID, p.id);
cv.put(OWNER_ID, p.owner_id);
cv.put(TITLE, p.title);
cv.put(SIZE, p.size);
cv.put(PRIVACY_VIEW, p.privacy_view == null ? null : p.privacy_view.toString());
cv.put(PRIVACY_COMMENT, p.privacy_comment == null ? null : p.privacy_comment.toString());
cv.put(DESCRIPTION, p.description);
cv.put(CAN_UPLOAD, p.can_upload);
cv.put(UPDATED, p.updated);
cv.put(CREATED, p.created);
if(Objects.nonNull(p.photo)){
cv.put(SIZES, GSON.toJson(Dto2Model.transform(p.photo)));
} else {
cv.putNull(SIZES);
}
cv.put(UPLOAD_BY_ADMINS, p.upload_by_admins_only);
cv.put(COMMENTS_DISABLED, p.comments_disabled);
return cv;
}
示例3: updateName
import android.content.ContentValues; //导入方法依赖的package包/类
@OnClick(R.id.btUpdate)
public void updateName(){
ContentValues contentValues = new ContentValues();
if (mCheckBoxNull.isChecked()) {
contentValues.put("NAME", (String)null);
} else {
contentValues.put("NAME", mETName.getEditableText().toString());
}
contentValues.put("FILTER", Integer.parseInt(mETFilter.getEditableText().toString()));
contentValues.putNull("SEND_TIME");
mDB.update("name", contentValues, "_id = ? ", new String[] {Long.toString(mId)});
finish();
}
示例4: resetUsage
import android.content.ContentValues; //导入方法依赖的package包/类
public void resetUsage(int uid) {
lock.writeLock().lock();
try {
// There is a segmented index on uid
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransactionNonExclusive();
try {
ContentValues cv = new ContentValues();
cv.putNull("sent");
cv.putNull("received");
cv.putNull("connections");
db.update("access", cv,
(uid < 0 ? null : "uid = ?"),
(uid < 0 ? null : new String[]{Integer.toString(uid)}));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
} finally {
lock.writeLock().unlock();
}
notifyAccessChanged();
}
示例5: deleteSelectedLabels
import android.content.ContentValues; //导入方法依赖的package包/类
private void deleteSelectedLabels(){
ContentResolver resolver = getContext().getContentResolver();
int size = selectedIds.size();
Long[] mArray = new Long[size];
for (int i = 0; i < size; i++) {
long id = selectedIds.keyAt(i);
mArray[i] = id;
}
// Update affected entries by label deletion
ContentValues cv = new ContentValues();
cv.putNull(ToduleDBContract.TodoEntry.COLUMN_NAME_LABEL);
String select = ToduleDBContract.TodoEntry.COLUMN_NAME_LABEL + " IN(" + constructPlaceholders(mArray.length)+ ")";
String[] selectionArgs = new String[mArray.length];
for (int i =0; i< mArray.length; i++){
selectionArgs[i] = String.valueOf(mArray[i]);
}
resolver.update(ToduleDBContract.TodoEntry.CONTENT_URI, cv, select ,selectionArgs);
// Delete label from db
select = TodoLabel._ID + " IN(" + constructPlaceholders(mArray.length)+ ")";
int count = resolver.delete(TodoLabel.CONTENT_URI, select, selectionArgs);
Toast.makeText(myActivity, String.valueOf(count) + " label deleted", Toast.LENGTH_SHORT).show();
}
示例6: restartDownload
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Restart the given downloads, which must have already completed (successfully or not). This
* method will only work when called from within the download manager's process.
* @param ids the IDs of the downloads
* @hide
*/
public void restartDownload(long... ids) {
Cursor cursor = query(new Query().setFilterById(ids));
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
int status = cursor.getInt(cursor.getColumnIndex(COLUMN_STATUS));
if (status != STATUS_SUCCESSFUL && status != STATUS_FAILED) {
throw new IllegalArgumentException("Cannot restart incomplete download: "
+ cursor.getLong(cursor.getColumnIndex(COLUMN_ID)));
}
}
} finally {
cursor.close();
}
ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0);
values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
values.putNull(Downloads.Impl._DATA);
values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PENDING);
values.put(Downloads.Impl.COLUMN_FAILED_CONNECTIONS, 0);
mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
}
示例7: saveUrl
import android.content.ContentValues; //导入方法依赖的package包/类
public void saveUrl(String url) {
ContentValues cv = new ContentValues();
cv.putNull(Entry.COLUMN_NAME_ID);
cv.put(Entry.COLUMN_NAME_URL, url);
cv.put(Entry.COLUMN_NAME_LAST_ACCESS, System.currentTimeMillis());
cv.put(Entry.COLUMN_NAME_NAME, getNameOfUrl(url));
save(cv);
}
示例8: saveUrl
import android.content.ContentValues; //导入方法依赖的package包/类
public void saveUrl(String url)
{
ContentValues cv = new ContentValues();
cv.putNull(Entry.COLUMN_NAME_ID);
cv.put(Entry.COLUMN_NAME_URL, url);
cv.put(Entry.COLUMN_NAME_LAST_ACCESS, System.currentTimeMillis());
cv.put(Entry.COLUMN_NAME_NAME, getNameOfUrl(url));
save(cv);
}
示例9: testNullColumnConstraints
import android.content.ContentValues; //导入方法依赖的package包/类
/**
>>>>>>> a6840f1... S07.03-Exercise-ConflictResolutionPolicy
* Tests the columns with null values cannot be inserted into the database.
*/
@Test
public void testNullColumnConstraints() {
/* Use a WeatherDbHelper to get access to a writable database */
/* We need a cursor from a weather table query to access the column names */
Cursor weatherTableCursor = database.query(
REFLECTED_TABLE_NAME,
/* We don't care about specifications, we just want the column names */
null, null, null, null, null, null);
/* Store the column names and close the cursor */
String[] weatherTableColumnNames = weatherTableCursor.getColumnNames();
weatherTableCursor.close();
/* Obtain weather values from TestUtilities and make a copy to avoid altering singleton */
ContentValues testValues = TestUtilities.createTestWeatherContentValues();
/* Create a copy of the testValues to save as a reference point to restore values */
ContentValues testValuesReferenceCopy = new ContentValues(testValues);
for (String columnName : weatherTableColumnNames) {
/* We don't need to verify the _ID column value is not null, the system does */
if (columnName.equals(WeatherContract.WeatherEntry._ID)) continue;
/* Set the value to null */
testValues.putNull(columnName);
/* Insert ContentValues into database and get a row ID back */
long shouldFailRowId = database.insert(
REFLECTED_TABLE_NAME,
null,
testValues);
String variableName = getConstantNameByStringValue(
WeatherContract.WeatherEntry.class,
columnName);
/* If the insert fails, which it should in this case, database.insert returns -1 */
String nullRowInsertShouldFail =
"Insert should have failed due to a null value for column: '" + columnName + "'"
+ ", but didn't."
+ "\n Check that you've added NOT NULL to " + variableName
+ " in your create table statement in the WeatherEntry class."
+ "\n Row ID: ";
assertEquals(nullRowInsertShouldFail,
-1,
shouldFailRowId);
/* "Restore" the original value in testValues */
testValues.put(columnName, testValuesReferenceCopy.getAsDouble(columnName));
}
/* Close database */
dbHelper.close();
}
示例10: getCV
import android.content.ContentValues; //导入方法依赖的package包/类
public static ContentValues getCV(NewsEntity dbo) {
ContentValues cv = new ContentValues();
cv.put(NewsColumns.TYPE, dbo.getType());
cv.put(NewsColumns.SOURCE_ID, dbo.getSourceId());
cv.put(NewsColumns.DATE, dbo.getDate());
cv.put(NewsColumns.POST_ID, dbo.getPostId());
cv.put(NewsColumns.POST_TYPE, dbo.getPostType());
cv.put(NewsColumns.FINAL_POST, dbo.isFinalPost());
cv.put(NewsColumns.COPY_OWNER_ID, dbo.getCopyOwnerId());
cv.put(NewsColumns.COPY_POST_ID, dbo.getCopyPostId());
cv.put(NewsColumns.COPY_POST_DATE, dbo.getCopyPostDate());
cv.put(NewsColumns.TEXT, dbo.getText());
cv.put(NewsColumns.CAN_EDIT, dbo.isCanEdit());
cv.put(NewsColumns.CAN_DELETE, dbo.isCanDelete());
cv.put(NewsColumns.COMMENT_COUNT, dbo.getCommentCount());
cv.put(NewsColumns.COMMENT_CAN_POST, dbo.isCanPostComment());
cv.put(NewsColumns.LIKE_COUNT, dbo.getLikesCount());
cv.put(NewsColumns.USER_LIKE, dbo.isUserLikes());
cv.put(NewsColumns.CAN_LIKE, dbo.isCanLike());
cv.put(NewsColumns.CAN_PUBLISH, dbo.isCanPublish());
cv.put(NewsColumns.REPOSTS_COUNT, dbo.getRepostCount());
cv.put(NewsColumns.USER_REPOSTED, dbo.isUserReposted());
cv.put(NewsColumns.GEO_ID, dbo.getGeoId());
cv.put(NewsColumns.TAG_FRIENDS, nonNull(dbo.getFriendsTags()) ? join(",", dbo.getFriendsTags()) : null);
cv.put(NewsColumns.VIEWS, dbo.getViews());
if (nonEmpty(dbo.getCopyHistory()) || nonEmpty(dbo.getAttachments())) {
List<Entity> attachmentsEntities = new ArrayList<>();
if (nonEmpty(dbo.getAttachments())) {
attachmentsEntities.addAll(dbo.getAttachments());
}
if (nonEmpty(dbo.getCopyHistory())) {
attachmentsEntities.addAll(dbo.getCopyHistory());
}
if (nonEmpty(attachmentsEntities)) {
AttachmentsEntity attachmentsEntity = new AttachmentsEntity(attachmentsEntities);
cv.put(NewsColumns.ATTACHMENTS_JSON, GSON.toJson(attachmentsEntity));
} else {
cv.putNull(NewsColumns.ATTACHMENTS_JSON);
}
}
return cv;
}
示例11: insertLog
import android.content.ContentValues; //导入方法依赖的package包/类
public void insertLog(Packet packet, String dname, int connection, boolean interactive) {
lock.writeLock().lock();
try {
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransactionNonExclusive();
try {
ContentValues cv = new ContentValues();
cv.put("time", packet.time);
cv.put("version", packet.version);
if (packet.protocol < 0)
cv.putNull("protocol");
else
cv.put("protocol", packet.protocol);
cv.put("flags", packet.flags);
cv.put("saddr", packet.saddr);
if (packet.sport < 0)
cv.putNull("sport");
else
cv.put("sport", packet.sport);
cv.put("daddr", packet.daddr);
if (packet.dport < 0)
cv.putNull("dport");
else
cv.put("dport", packet.dport);
if (dname == null)
cv.putNull("dname");
else
cv.put("dname", dname);
cv.put("data", packet.data);
if (packet.uid < 0)
cv.putNull("uid");
else
cv.put("uid", packet.uid);
cv.put("allowed", packet.allowed ? 1 : 0);
cv.put("connection", connection);
cv.put("interactive", interactive ? 1 : 0);
if (db.insert("log", null, cv) == -1)
Log.e(TAG, "Insert log failed");
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
} finally {
lock.writeLock().unlock();
}
notifyLogChanged();
}