Code example for SQLiteDatabase

Methods: insertinsertOrThrowrawQueryupdate

1
		ftsVals.put(C_DESC, values.getAsString(C_DESC));
		ftsVals.put(C_NAME, values.getAsString(C_NAME));
		ftsVals.put(C_LAST_MODIFIED, values.getAsLong(C_LAST_MODIFIED));
		ftsVals.put(C_SUPERVISOR, values.getAsString(C_SUPERVISOR));
		try { 
			db.insertOrThrow(TASK_TABLE, null, values);
			db.insert(FTS_TABLE, null, ftsVals);
		} catch (SQLException e) {
			Log.d(TAG, "exception: " + e.getLocalizedMessage());
			Long id = values.getAsLong(C_ID);
			Cursor cursor = db.rawQuery("SELECT version FROM " + TASK_TABLE +
					" WHERE " + C_ID + " = " + Long.toString(id), null);
			if( cursor != null ) {
				Long remote_ver = values.getAsLong(C_VERSION);
				cursor.moveToFirst(); 
				if(cursor.getLong(0) != remote_ver) {
					db.update(TASK_TABLE, values, C_ID + " = " + id, null);
					db.update(FTS_TABLE, ftsVals, C_ID + " = " + id, null);
					Log.d(TAG, "duplicate id, task was updated");
				} 
			} 
			cursor.close();
		}