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


Java SQLiteDatabase.insertWithOnConflict方法代码示例

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


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

示例1: logBookAccess

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
void logBookAccess(int bookId) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValue = new ContentValues();
    contentValue.put(UserDataDBContract.AccessInformationEntry.COLUMN_NAME_BOOK_ID, bookId);
    db.insertWithOnConflict(UserDataDBContract.AccessInformationEntry.Table_NAME,
            null,
            contentValue,
            SQLiteDatabase.CONFLICT_IGNORE);

    db.execSQL(" UPDATE " +
                    UserDataDBContract.AccessInformationEntry.Table_NAME +
                    " SET " + UserDataDBContract.AccessInformationEntry.COLUMN_ACCESS_COUNT + "=" +
                    UserDataDBContract.AccessInformationEntry.COLUMN_ACCESS_COUNT + "+1" +
                    SQL.WHERE + UserDataDBContract.AccessInformationEntry.COLUMN_NAME_BOOK_ID + "=?",
            new String[]{String.valueOf(bookId)});
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:17,代码来源:UserDataDBHelper.java

示例2: bulkInsertEnergyUseLogs

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Inclusão em bloco dos logs de utilização de energia.
 */
private int bulkInsertEnergyUseLogs(@NonNull Uri uri, @NonNull ContentValues[] values, SQLiteDatabase sqLiteDatabase) {
    sqLiteDatabase.beginTransaction();
    //Armazenar as datas dos novos logs para atualizar o cache de  utilização de energia.
    Set<Long> setDateUpdated = new TreeSet<>();
    try {
        for (int row = 0; row < values.length; row++) {
            ContentValues value = values[row];
            long insertedResult = sqLiteDatabase.insertWithOnConflict(
                    EnergyUseLogEntry.TABLE_NAME,
                    null,
                    value,
                    SQLiteDatabase.CONFLICT_REPLACE);
            if (insertedResult == -1) {
                throw new SQLException(String.format("The EnergyUseLog content on the row %s It is not valid.", row));
            }
            setDateUpdated.add(value.getAsLong(EnergyUseLogEntry._ID));
        }
        sqLiteDatabase.setTransactionSuccessful();
    } finally {
        sqLiteDatabase.endTransaction();
    }
    //Atualizar o cache de  utilização de energia.
    updateEnergyUseTotalOnCache(setDateUpdated);
    //Notificar a atualização para as Uri relacionadas a tabela EnergyUseLog
    notifyUpdatedEntities(uri);
    return values.length;
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:31,代码来源:OhaEnergyUseProvider.java

示例3: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(@NonNull Uri uri, ContentValues[] values) {

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    final int match = mUriMatcher.match(uri);
    int returnCount = 0;
    switch (match) {
        case FARMACIAS:
            db.beginTransaction();

            try {
                for (ContentValues value : values) {
                    long _id = db.insertWithOnConflict(DbContract.FarmaciasEntity.TABLE_NAME, null, value, SQLiteDatabase.CONFLICT_REPLACE);
                    if (_id != -1) {
                        returnCount++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
            getContext().getContentResolver().notifyChange(uri, null);
            return returnCount;

        default:
            return super.bulkInsert(uri, values);
    }


}
 
开发者ID:cahergil,项目名称:Farmacias,代码行数:31,代码来源:DbProvider.java

示例4: insertTimetablePeriod

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertTimetablePeriod(int id, String startTime, String endTime, String timetableID) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_PERIOD_ID, id);
    contentValues.put(COL_START_TIME, startTime);
    contentValues.put(COL_END_TIME, endTime);
    contentValues.put(COL_TIMETABLE_ID, timetableID);
    long result = db.insertWithOnConflict(TABLE_PERIODS, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
    return result != -1;
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:11,代码来源:TimetableDatabaseHelper.java

示例5: ContentValues

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Sets the value for the key given, returns true if successful, false otherwise.
 */
/* package */ static boolean setItemImpl(SQLiteDatabase db, String key, String value) {
  ContentValues contentValues = new ContentValues();
  contentValues.put(KEY_COLUMN, key);
  contentValues.put(VALUE_COLUMN, value);

  long inserted = db.insertWithOnConflict(
      TABLE_CATALYST,
      null,
      contentValues,
      SQLiteDatabase.CONFLICT_REPLACE);

  return (-1 != inserted);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:17,代码来源:AsyncLocalStorageUtil.java

示例6: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    switch (sUriMatcher.match(uri)) {
        case VIDEO: {
            final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            int returnCount = 0;

            db.beginTransaction();
            try {
                for (ContentValues value : values) {
                    long _id = db.insertWithOnConflict(VideoContract.VideoEntry.TABLE_NAME,
                            null, value, SQLiteDatabase.CONFLICT_REPLACE);
                    if (_id != -1) {
                        returnCount++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            mContentResolver.notifyChange(uri, null);
            return returnCount;
        }
        default: {
            return super.bulkInsert(uri, values);
        }
    }
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:30,代码来源:VideoProvider.java

示例7: insertTimetableTeacher

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertTimetableTeacher(int id, String name, String shortname, int colour, String timetableID) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_TEACHER_ID, id);
    contentValues.put(COL_NAME, name);
    contentValues.put(COL_SHORT_NAME, shortname);
    contentValues.put(COL_COLOUR, colour);
    contentValues.put(COL_TIMETABLE_ID, timetableID);
    long result = db.insertWithOnConflict(TABLE_TEACHERS, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
    return result != -1;
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:12,代码来源:TimetableDatabaseHelper.java

示例8: addArtistMetaData

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void addArtistMetaData(SQLiteDatabase sqLiteDatabase, Artist artist) {
    ContentValues values = new ContentValues();
    values.put(ArtistId, artist.getId());
    values.put(ArtistTitle, artist.getName());
    values.put(ArtistAlbumCount, artist.getAlbumCount());
    values.put(ArtistTrackCount, artist.getTrackCount());
    sqLiteDatabase.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_IGNORE);
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:9,代码来源:CommonDatabase.java

示例9: insertSync

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * 插入数据,此为同步方法
 */
private void insertSync(List<String> idList, List<String> valueList) {
  SQLiteDatabase db = getWritableDatabase();
  db.beginTransaction();
  for (int i = 0; i < valueList.size(); i++) {
    ContentValues values = new ContentValues();
    values.put(TABLE_KEY_ID, idList.get(i));
    values.put(TABLE_KEY_CONTENT, valueList.get(0));
    db.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_REPLACE);
  }
  db.setTransactionSuccessful();
  db.endTransaction();
}
 
开发者ID:linsir6,项目名称:TripBuyer,代码行数:16,代码来源:LCIMLocalStorage.java

示例10: addSongMetaData

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void addSongMetaData(SQLiteDatabase sqLiteDatabase, Song song) {
    ContentValues values = new ContentValues();
    values.put(SongId, song.getId());
    values.put(SongTitle, song.getTitle());
    values.put(SongAlbum, song.getAlbum());
    values.put(SongArtist, song.getArtist());
    values.put(SongNumber, song.getTrackNumber());
    values.put(SongPath, song.getmSongPath());
    values.put(SongAlbumId, song.getAlbumId());
    sqLiteDatabase.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_IGNORE);
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:12,代码来源:CommonDatabase.java

示例11: insertUser

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void insertUser(int userid, String userName, SqliteTestDbOpenHelper helper) {
    SQLiteDatabase db = helper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("userid", userid);
    values.put("username", userName);

    db.insertWithOnConflict("users", null, values,
            SQLiteDatabase.CONFLICT_REPLACE);

    db.close();
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:12,代码来源:SqliteDatabaseTestHelper.java

示例12: insertOrUpdateUser

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void insertOrUpdateUser(User user) {
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(COLUMN_NAME_ENTRY_ID, user.getId());
    values.put(COLUMN_NAME_USERNAME, user.getUserName());

    db.insertWithOnConflict(TABLE_NAME, null, values,
            SQLiteDatabase.CONFLICT_REPLACE);

    db.close();
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:14,代码来源:LocalUserDataSource.java

示例13: insertTimetableMeta

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertTimetableMeta(String timetable_id, long modified) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_TIMETABLE_ID, timetable_id);
    contentValues.put(COL_MODIFIED_MILLIS, modified);
    long result = db.insertWithOnConflict(TABLE_META, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
    return result != -1;
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:9,代码来源:TimetableDatabaseHelper.java

示例14: insertTimetableForm

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertTimetableForm(int id, String name, String shortname, int teacherid, String timetableID) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_FORM_ID, id);
    contentValues.put(COL_NAME, name);
    contentValues.put(COL_SHORT_NAME, shortname);
    contentValues.put(COL_TEACHER_ID, teacherid);
    contentValues.put(COL_TIMETABLE_ID, timetableID);
    long result = db.insertWithOnConflict(TABLE_FORMS, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
    return result != -1;
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:12,代码来源:TimetableDatabaseHelper.java

示例15: insert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
    if(values==null) {
        throw new IllegalArgumentException("Values are null");
    }
    final SQLiteDatabase db=database.getWritableDatabase();
    final MusicMatchEnum matchEnum=matcher.match(uri);
    if(matchEnum.table!=null){
        db.insertWithOnConflict(matchEnum.table,null,values,SQLiteDatabase.CONFLICT_REPLACE);
        notifyChange(uri);
    }
    return null;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:15,代码来源:MusicProvider.java


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