List of usage examples for android.database.sqlite SQLiteDatabase insertWithOnConflict
public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm)
From source file:co.rewen.statex.AsyncLocalStorageUtil.java
/** * Sets the value for the key given, returns true if successful, false otherwise. *///from w w w .jav a2 s . co m /* 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_STATE, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE); return (-1 != inserted); }
From source file:com.shalzz.attendance.DatabaseHandler.java
public void addUser(User user) { SQLiteDatabase db = this.getWritableDatabase(); db.insertWithOnConflict( User.TABLE_NAME, null, User.FACTORY.marshal().sap_id(user.sap_id()).name(user.name()) .course(user.course()).password(user.password()).asContentValues(), SQLiteDatabase.CONFLICT_REPLACE); }
From source file:com.shalzz.attendance.DatabaseHandler.java
public void addPeriod(Period period, long timestamp) { SQLiteDatabase db = this.getWritableDatabase(); db.insertWithOnConflict(Period.TABLE_NAME, null, Period.FACTORY.marshal().id(period.id()).name(period.name()).week_day(period.week_day()) .teacher(Miscellaneous.capitalizeString(period.teacher())).room(period.room().trim()) .start_time(period.start_time()).end_time(period.end_time()).batch(period.batch()) .last_updated(timestamp).asContentValues(), SQLiteDatabase.CONFLICT_REPLACE); }
From source file:com.shalzz.attendance.DatabaseHandler.java
/** * Add new Subject//from ww w . j av a 2 s . co m * @param subject the {@link Subject} to add */ public void addSubject(Subject subject, long timestamp) { SQLiteDatabase db = getWritableDatabase(); db.insertWithOnConflict(Subject.TABLE_NAME, null, Subject.FACTORY.marshal().id(subject.id()).name(subject.name()).attended(subject.attended()) .held(subject.held()).last_updated(timestamp).asContentValues(), SQLiteDatabase.CONFLICT_REPLACE); // Store the dates in another table corresponding to the same id for (Date date : subject.absent_dates()) { db.insertWithOnConflict(AbsentDate.TABLE_NAME, null, AbsentDate.FACTORY.marshal().subject_id(subject.id()).absent_date(date).asContentValues(), SQLiteDatabase.CONFLICT_IGNORE); } }
From source file:company.test.Test.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch (id) { case R.id.add_item: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Add a task"); builder.setMessage("What do you want to do?"); final EditText inputField = new EditText(this); builder.setView(inputField);/* w ww .ja v a2 s .c o m*/ builder.setPositiveButton("Add", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { String task = inputField.getText().toString(); Log.d("MainActivity", task); SQLiteDatabase db = helper.getWritableDatabase(); ContentValues values = new ContentValues(); values.clear(); values.put(ItemContract.Columns.ITEM, task); db.insertWithOnConflict(ItemContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE); activity.updateUI(); } }); builder.setNegativeButton("Cancel", null); builder.create().show(); return true; case R.id.action_settings: Log.d("MainActivity", "Settings"); return true; default: return false; } }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void insertVideo(SQLiteDatabase tempDb, ContentValues values) { tempDb.insertWithOnConflict(videoTableName, null, values, SQLiteDatabase.CONFLICT_IGNORE); }
From source file:com.xengar.android.englishverbs.data.VerbDBHelper.java
/** * Insert the 5 most common verbs./*from w w w . ja va 2 s . c om*/ * @param db SQLiteDatabase */ private void insertFavorites(SQLiteDatabase db) { ContentValues values = new ContentValues(); for (int i = 0; i < favorites.length; i++) { values.put("_id", i); values.put(VerbEntry.COLUMN_ID, favorites[i][0]); db.insertWithOnConflict(VerbEntry.FAVORITES_TBL, null, values, CONFLICT_REPLACE); } }
From source file:github.popeen.dsub.util.SongDBHandler.java
protected synchronized void addSongImpl(SQLiteDatabase db, int serverKey, String id, String absolutePath) { ContentValues values = new ContentValues(); values.put(SONGS_SERVER_KEY, serverKey); values.put(SONGS_SERVER_ID, id);/* w w w . jav a 2 s . c om*/ values.put(SONGS_COMPLETE_PATH, absolutePath); db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE); }
From source file:at.bitfire.davdroid.ui.setup.AccountDetailsFragment.java
protected long insertService(SQLiteDatabase db, String accountName, String service, DavResourceFinder.Configuration.ServiceInfo info) { ContentValues values = new ContentValues(); // insert service values.put(Services.ACCOUNT_NAME, accountName); values.put(Services.SERVICE, service); if (info.principal != null) values.put(Services.PRINCIPAL, info.principal.toString()); long serviceID = db.insertWithOnConflict(Services._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); // insert home sets for (URI homeSet : info.homeSets) { values.clear();//from w ww .j a v a 2 s . c om values.put(HomeSets.SERVICE_ID, serviceID); values.put(HomeSets.URL, homeSet.toString()); db.insertWithOnConflict(HomeSets._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } // insert collections for (CollectionInfo collection : info.collections.values()) { values = collection.toDB(); values.put(Collections.SERVICE_ID, serviceID); db.insertWithOnConflict(Collections._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } return serviceID; }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void insertTopicVideo(SQLiteDatabase tempDb, ContentValues values) { // This values is for a video. ContentValues v = new ContentValues(); v.put("topic_id", values.getAsString("parentTopic_id")); v.put("video_id", values.getAsString("readable_id")); tempDb.insertWithOnConflict(topicvideoTableName, null, v, SQLiteDatabase.CONFLICT_IGNORE); }