List of usage examples for android.database.sqlite SQLiteDatabase update
public int update(String table, ContentValues values, String whereClause, String[] whereArgs)
From source file:ru.valle.safetrade.SellActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { String scannedResult = data.getStringExtra("data"); if (scannedResult != null) { switch (requestCode) { case REQUEST_SCAN_CONFIRMATION_CODE: { if (scannedResult.startsWith("cfrm")) { checkConfirmationCodeToDecodeAddress(scannedResult); } else if (scannedResult.startsWith("passphrase")) { showAlert(getString(R.string.not_confirmation_but_intermediate_code)); } else { showAlert(getString(R.string.not_confirmation_code)); }//w w w . jav a2 s . c o m } break; case REQUEST_SCAN_PRIVATE_KEY: { if (scannedResult.startsWith("6P")) { savePrivateKey(scannedResult); } else { showAlert(getString(R.string.not_encrypted_private_key)); } } break; case REQUEST_SCAN_FINAL_ADDRESS: { final String address; if (scannedResult.startsWith(SCHEME_BITCOIN)) { scannedResult = scannedResult.substring(SCHEME_BITCOIN.length()); int queryStartIndex = scannedResult.indexOf('?'); address = queryStartIndex == -1 ? scannedResult : scannedResult.substring(0, queryStartIndex); } else if (scannedResult.startsWith("1")) { address = scannedResult; } else { showAlert(getString(R.string.not_address)); address = null; } if (!TextUtils.isEmpty(address)) { finalAddressView.setText(address); final long id = rowId; new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { SQLiteDatabase db = DatabaseHelper.getInstance(SellActivity.this) .getWritableDatabase(); if (db != null) { ContentValues cv = new ContentValues(); cv.put(DatabaseHelper.COLUMN_FINAL_ADDRESS, address); db.update(DatabaseHelper.TABLE_HISTORY, cv, BaseColumns._ID + "=?", new String[] { String.valueOf(id) }); } return null; } }.execute(); } } break; } } } }
From source file:net.potterpcs.recipebook.RecipeData.java
public int updateRecipe(long rid, ContentValues values) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int ret = -1; try {/*w w w.j a v a 2s . c o m*/ ret = db.update(RECIPES_TABLE, values, RT_ID + " = ?", new String[] { Long.toString(rid) }); } finally { db.close(); } return ret; } }
From source file:ru.valle.safetrade.SellActivity.java
private void checkConfirmationCodeToDecodeAddress(final String confirmationCode) { final String password = tradeInfo.password; final long id = rowId; confirmationCodeDecodingTask = new AsyncTask<Void, String, String>() { public ProgressDialog progressDialog; @Override/*from ww w. j av a2s .com*/ protected void onPreExecute() { final CharSequence oldEnteredValue = confirmationCodeView.getText(); confirmationCodeView.setText(confirmationCode); progressDialog = ProgressDialog.show(SellActivity.this, null, getString(R.string.decoding_confirmation_code_using_password), true); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { confirmationCodeDecodingTask.cancel(true); confirmationCodeView.setText(oldEnteredValue); if (rowId != -1) { loadState(rowId); } } }); } @Override protected void onProgressUpdate(String... values) { try { progressDialog.setMessage(values[0]); } catch (Exception ignored) { } } @Override protected String doInBackground(Void... params) { try { String address = BTCUtils.bip38DecryptConfirmation(confirmationCode, password); if (address != null) { SQLiteDatabase db = DatabaseHelper.getInstance(SellActivity.this).getWritableDatabase(); if (db != null) { ContentValues cv = new ContentValues(); cv.put(DatabaseHelper.COLUMN_ADDRESS, address); cv.put(DatabaseHelper.COLUMN_CONFIRMATION_CODE, confirmationCode); db.update(DatabaseHelper.TABLE_HISTORY, cv, BaseColumns._ID + "=?", new String[] { String.valueOf(id) }); } } return address; } catch (Throwable e) { return null; } } @Override protected void onPostExecute(final String address) { try { progressDialog.dismiss(); } catch (Exception ignored) { } confirmationCodeDecodingTask = null; if (!TextUtils.isEmpty(address)) { confirmationCodeView.setText(confirmationCode); addressView.setText(address); addressLabelView.setVisibility(View.VISIBLE); addressView.setVisibility(View.VISIBLE); MainActivity.updateBalance(SellActivity.this, id, address, onAddressStateReceivedListener); } else { loadState(rowId); showAlert(getString(R.string.confirmation_code_doesnt_match)); } } }.execute(); }
From source file:com.csipsimple.db.DBProvider.java
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;/*w ww.ja va 2s. c om*/ String finalWhere; int matched = URI_MATCHER.match(uri); List<String> possibles = getPossibleFieldsForType(matched); checkSelection(possibles, where); switch (matched) { case ACCOUNTS: count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, where, whereArgs); break; case ACCOUNTS_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, finalWhere, whereArgs); break; case CALLLOGS: count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, where, whereArgs); break; case CALLLOGS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, finalWhere, whereArgs); break; case FILTERS: count = db.update(SipManager.FILTERS_TABLE_NAME, values, where, whereArgs); break; case FILTERS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.FILTERS_TABLE_NAME, values, finalWhere, whereArgs); break; case MESSAGES: count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); break; case MESSAGES_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); break; case ACCOUNTS_STATUS_ID: long id = ContentUris.parseId(uri); synchronized (profilesStatus) { SipProfileState ps = new SipProfileState(); if (profilesStatus.containsKey(id)) { ContentValues currentValues = profilesStatus.get(id); ps.createFromContentValue(currentValues); } ps.createFromContentValue(values); ContentValues cv = ps.getAsContentValue(); cv.put(SipProfileState.ACCOUNT_ID, id); profilesStatus.put(id, cv); Log.d(THIS_FILE, "Updated " + cv); } count = 1; break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } getContext().getContentResolver().notifyChange(uri, null); long rowId = -1; if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) { rowId = ContentUris.parseId(uri); } if (rowId >= 0) { if (matched == ACCOUNTS_ID) { // Don't broadcast if we only changed wizard or only changed priority boolean doBroadcast = true; if (values.size() == 1) { if (values.containsKey(SipProfile.FIELD_WIZARD)) { doBroadcast = false; } else if (values.containsKey(SipProfile.FIELD_PRIORITY)) { doBroadcast = false; } } if (doBroadcast) { broadcastAccountChange(rowId); } } else if (matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } return count; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
private void postFavoriteToServer(final FavoritesData fd, Context context, boolean spawnThread) { if (IbikeApplication.isUserLogedIn()) { String authToken = IbikeApplication.getAuthToken(); final JSONObject postObject = new JSONObject(); try {// www . j a v a 2 s . c o m JSONObject favouriteObject = new JSONObject(); favouriteObject.put("name", fd.getName()); favouriteObject.put("address", fd.getAdress()); favouriteObject.put("lattitude", fd.getLatitude()); favouriteObject.put("longitude", fd.getLongitude()); favouriteObject.put("source", fd.getSource()); favouriteObject.put("sub_source", fd.getSubSource()); postObject.put("favourite", favouriteObject); postObject.put("auth_token", authToken); if (spawnThread) { Thread thread = new Thread(new Runnable() { @Override public void run() { LOG.d("Server request: " + Config.serverUrl + "/favourites"); JsonNode responseNode = HttpUtils.postToServer(Config.serverUrl + "/favourites", postObject); if (responseNode != null && responseNode.has("data") && responseNode.get("data").has("id")) { int id = responseNode.get("data").get("id").asInt(); SQLiteDatabase db = getWritableDatabase(); if (db == null) return; String strFilter = "_id=" + fd.getId(); ContentValues args = new ContentValues(); args.put(KEY_API_ID, id); db.update(TABLE_FAVORITES, args, strFilter, null); db.close(); } } }); thread.start(); } else { LOG.d("Server request: " + Config.serverUrl + "/favourites"); JsonNode responseNode = HttpUtils.postToServer(Config.serverUrl + "/favourites", postObject); if (responseNode != null && responseNode.has("data") && responseNode.get("data").has("id")) { int id = responseNode.get("data").get("id").asInt(); SQLiteDatabase db = getWritableDatabase(); if (db == null) return; String strFilter = "_id=" + fd.getId(); ContentValues args = new ContentValues(); args.put(KEY_API_ID, id); db.update(TABLE_FAVORITES, args, strFilter, null); db.close(); } } } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } } }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void updateFavorite(FavoritesData fd, Context context, APIListener listener) { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;/*from www.ja v a2 s .co m*/ ContentValues values = new ContentValues(); values.put(KEY_NAME, fd.getName()); values.put(KEY_ADDRESS, fd.getAdress()); values.put(KEY_SOURCE, fd.getSource()); values.put(KEY_SUBSOURCE, fd.getSubSource()); values.put(KEY_LAT, Double.valueOf(fd.getLatitude())); values.put(KEY_LONG, Double.valueOf(fd.getLongitude())); db.update(TABLE_FAVORITES, values, KEY_ID + " = ?", new String[] { "" + fd.getId() }); db.close(); if (context != null) updateFavoriteToServer(fd, context, listener); }
From source file:net.potterpcs.recipebook.RecipeData.java
public int updateRecipe(Recipe r) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int ret = -1; try {//from w w w. j a v a 2s . co m long rid = r.id; String[] whereArgs = { Long.toString(rid) }; ret = db.update(RECIPES_TABLE, createRecipeForInsert(r), RT_ID + " = ?", new String[] { Long.toString(r.id) }); // TODO until we can figure out a smarter way to update db.delete(INGREDIENTS_TABLE, IT_RECIPE_ID + " = ?", whereArgs); for (String ing : r.ingredients) { db.insertWithOnConflict(INGREDIENTS_TABLE, null, createIngredientsCV(rid, ing), SQLiteDatabase.CONFLICT_IGNORE); } db.delete(DIRECTIONS_TABLE, DT_RECIPE_ID + " = ?", whereArgs); int step = 1; for (String dir : r.directions) { db.insertWithOnConflict(DIRECTIONS_TABLE, null, createDirectionsCV(rid, step, dir, r.directions_photos[step - 1]), SQLiteDatabase.CONFLICT_IGNORE); step++; } db.delete(TAGS_TABLE, TT_RECIPE_ID + " = ?", whereArgs); for (String tag : r.tags) { db.insertWithOnConflict(TAGS_TABLE, null, createTagsCV(rid, tag), SQLiteDatabase.CONFLICT_IGNORE); } } finally { db.close(); } return ret; } }
From source file:net.potterpcs.recipebook.RecipeData.java
public void insertCacheEntry(String uri, String cached) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(CT_URI, uri);//from w w w. ja v a 2s.c o m values.put(CT_CACHED, cached); if (isCached(uri)) { db.update(CACHE_TABLE, values, CT_URI + " = ?", new String[] { cached }); } else { db.insert(CACHE_TABLE, null, values); } } }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public int updateResponseFilter(ResponseFilter responseFilter) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_CONTENT, responseFilter.getContent().trim()); values.put(KEY_SOURCE, responseFilter.getSource()); values.put(KEY_MODIFIED, getDateTime()); // updating row return db.update(TABLE_RESPONSE_FILTERS, values, KEY_ID + " = ?", new String[] { String.valueOf(responseFilter.getId()) }); }
From source file:net.smart_json_database.JSONDatabase.java
/** * Insert or update a property to db/* ww w.j a v a 2 s. co m*/ * * @param key * @param value * @return */ public long setProperty(String key, String value) { SQLiteDatabase db = dbHelper.getWritableDatabase(); String checkKey = Util.DateToString(new Date()); ContentValues values = new ContentValues(); values.put("value", value); long i = -1; if (checkKey.equals(getPropterty(db, key, checkKey))) { values.put("key", key); i = db.insert(TABLE_Meta, null, values); } else { i = db.update(TABLE_Meta, values, "key = ?", new String[] { key }); } db.close(); return i; }