List of usage examples for android.database.sqlite SQLiteDatabase delete
public int delete(String table, String whereClause, String[] whereArgs)
From source file:net.potterpcs.recipebook.RecipeData.java
public void removeCacheEntry(String uri) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); if (isCached(uri)) { db.delete(CACHE_TABLE, CT_URI + "= ?", new String[] { uri }); }//from w w w . j a va2s. c om } }
From source file:com.appsimobile.appsii.module.home.provider.HomeContentProvider.java
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); try {/*from w w w . j a v a2 s . co m*/ int count = db.delete(args.table, args.where, args.args); if (count > 0) sendNotify(uri); return count; } catch (SQLiteConstraintException e) { SQLiteConstraintException ex = new SQLiteConstraintException( "Constraint violation on delete of: " + uri); ex.initCause(e); throw ex; } }
From source file:net.voxcorp.voxmobile.db.DBProvider.java
@Override public int delete(Uri uri, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); String finalWhere;//from w ww. j a v a 2 s.c om int count = 0; int matched = URI_MATCHER.match(uri); Uri regUri = uri; List<String> possibles = getPossibleFieldsForType(matched); checkSelection(possibles, where); ArrayList<Long> oldRegistrationsAccounts = null; switch (matched) { case ACCOUNTS: count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, where, whereArgs); break; case ACCOUNTS_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, finalWhere, whereArgs); break; case CALLLOGS: count = db.delete(SipManager.CALLLOGS_TABLE_NAME, where, whereArgs); break; case CALLLOGS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipManager.CALLLOGS_TABLE_NAME, finalWhere, whereArgs); break; case FILTERS: count = db.delete(SipManager.FILTERS_TABLE_NAME, where, whereArgs); break; case FILTERS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipManager.FILTERS_TABLE_NAME, finalWhere, whereArgs); break; case MESSAGES: count = db.delete(SipMessage.MESSAGES_TABLE_NAME, where, whereArgs); break; case MESSAGES_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipMessage.MESSAGES_TABLE_NAME, finalWhere, whereArgs); break; case THREADS_ID: String from = uri.getLastPathSegment(); if (!TextUtils.isEmpty(from)) { count = db.delete(SipMessage.MESSAGES_TABLE_NAME, MESSAGES_THREAD_SELECTION, new String[] { from, from }); } else { count = 0; } regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: oldRegistrationsAccounts = new ArrayList<Long>(); synchronized (profilesStatus) { for (Long accId : profilesStatus.keySet()) { oldRegistrationsAccounts.add(accId); } profilesStatus.clear(); } break; case ACCOUNTS_STATUS_ID: long id = ContentUris.parseId(uri); synchronized (profilesStatus) { profilesStatus.remove(id); } break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } getContext().getContentResolver().notifyChange(regUri, null); if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) { long rowId = ContentUris.parseId(uri); if (rowId >= 0) { if (matched == ACCOUNTS_ID) { broadcastAccountChange(rowId); } else if (matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } } } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } if (matched == ACCOUNTS_STATUS && oldRegistrationsAccounts != null) { for (Long accId : oldRegistrationsAccounts) { if (accId != null) { broadcastRegistrationChange(accId); } } } return count; }
From source file:com.csipsimple.db.DBProvider.java
@Override public int delete(Uri uri, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); String finalWhere;// w w w.j av a 2s .c om int count = 0; int matched = URI_MATCHER.match(uri); Uri regUri = uri; List<String> possibles = getPossibleFieldsForType(matched); checkSelection(possibles, where); ArrayList<Long> oldRegistrationsAccounts = null; switch (matched) { case ACCOUNTS: count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, where, whereArgs); break; case ACCOUNTS_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, finalWhere, whereArgs); break; case CALLLOGS: count = db.delete(SipManager.CALLLOGS_TABLE_NAME, where, whereArgs); break; case CALLLOGS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipManager.CALLLOGS_TABLE_NAME, finalWhere, whereArgs); break; case FILTERS: count = db.delete(SipManager.FILTERS_TABLE_NAME, where, whereArgs); break; case FILTERS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipManager.FILTERS_TABLE_NAME, finalWhere, whereArgs); break; case MESSAGES: count = db.delete(SipMessage.MESSAGES_TABLE_NAME, where, whereArgs); break; case MESSAGES_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.delete(SipMessage.MESSAGES_TABLE_NAME, finalWhere, whereArgs); break; case THREADS_ID: String from = uri.getLastPathSegment(); if (!TextUtils.isEmpty(from)) { count = db.delete(SipMessage.MESSAGES_TABLE_NAME, MESSAGES_THREAD_SELECTION, new String[] { from, from }); } else { count = 0; } regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: oldRegistrationsAccounts = new ArrayList<Long>(); synchronized (profilesStatus) { for (Long accId : profilesStatus.keySet()) { oldRegistrationsAccounts.add(accId); } profilesStatus.clear(); } break; case ACCOUNTS_STATUS_ID: long id = ContentUris.parseId(uri); synchronized (profilesStatus) { profilesStatus.remove(id); } break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } getContext().getContentResolver().notifyChange(regUri, null); if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) { long rowId = ContentUris.parseId(uri); if (rowId >= 0) { if (matched == ACCOUNTS_ID) { broadcastAccountDelete(rowId); } else if (matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } } } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } if (matched == ACCOUNTS_STATUS && oldRegistrationsAccounts != null) { for (Long accId : oldRegistrationsAccounts) { if (accId != null) { broadcastRegistrationChange(accId); } } } return count; }
From source file:org.ohmage.db.DbHelper.java
/** * Utility method that populates the Survey and SurveyPrompt tables for the * campaign identified by campaignUrn and containing the given xml as * campaignXML.// www .j a va 2 s . c o m * * Note that this method takes a db handle so that it can be used in a * transaction. * * @param db * a handle to an existing writable db * @param campaignUrn * the urn of the campaign for which we're populating subtables * @param campaignXML * the XML for the campaign (not validated by this method) * @return * */ public boolean populateSurveysFromCampaignXML(SQLiteDatabase db, String campaignUrn, String campaignXML) { try { // dump all the surveys (and consequently survey prompts) before we // do anything // this is (perhaps surprisingly) desired behavior, as the surveys + // survey prompts // should always reflect the state of the campaign XML, valid or not db.delete(Tables.SURVEYS, Surveys.CAMPAIGN_URN + "=?", new String[] { campaignUrn }); // do a pass over the XML to gather surveys and survey prompts XmlPullParser xpp = Xml.newPullParser(); xpp.setInput(new ByteArrayInputStream(campaignXML.getBytes("UTF-8")), "UTF-8"); int eventType = xpp.getEventType(); String tagName; // various stacks to maintain state while walking through the xml // tree Stack<String> tagStack = new Stack<String>(); Survey curSurvey = null; // valid only within a survey, null // otherwise Vector<SurveyPrompt> prompts = new Vector<SurveyPrompt>(); // valid // only // within // a // survey, // empty // otherwise Vector<JSONObject> properties = new Vector<JSONObject>(); // valid // only // within // a // prompt, // empty // otherwise // iterate through the xml, paying attention only to surveys and // prompts // note that this does no validation outside of preventing itself // from crashing catastrophically while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { tagName = xpp.getName(); tagStack.push(tagName); if (tagName.equalsIgnoreCase("survey")) { if (curSurvey != null) throw new XmlPullParserException("encountered a survey tag inside another survey tag"); curSurvey = new Survey(); curSurvey.mCampaignUrn = campaignUrn; } else if (tagName.equalsIgnoreCase("prompt")) { SurveyPrompt sp = new SurveyPrompt(); // FIXME: add the campaign + survey ID to make lookups // easier? prompts.add(sp); } else if (tagName.equalsIgnoreCase("property")) { properties.add(new JSONObject()); } } else if (eventType == XmlPullParser.TEXT) { if (tagStack.size() >= 2) { // we may be in an entity>property situation, so check // and assign accordingly if (tagStack.get(tagStack.size() - 2).equalsIgnoreCase("survey")) { // populating the current survey object with its // properties here if (tagStack.peek().equalsIgnoreCase("id")) curSurvey.mSurveyID = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("title")) curSurvey.mTitle = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("description")) curSurvey.mDescription = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("submitText")) curSurvey.mSubmitText = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("showSummary")) curSurvey.mShowSummary = xpp.getText().equals("true") ? true : false; else if (tagStack.peek().equalsIgnoreCase("editSummary")) curSurvey.mEditSummary = xpp.getText().equals("true") ? true : false; else if (tagStack.peek().equalsIgnoreCase("summaryText")) curSurvey.mSummaryText = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("introText")) curSurvey.mIntroText = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("anytime")) curSurvey.mAnytime = xpp.getText().equals("true") ? true : false; } else if (tagStack.get(tagStack.size() - 2).equalsIgnoreCase("prompt")) { SurveyPrompt sp = prompts.lastElement(); // populating the last encountered survey prompt // with its properties here if (tagStack.peek().equalsIgnoreCase("id")) sp.mPromptID = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("promptText")) sp.mPromptText = xpp.getText(); else if (tagStack.peek().equalsIgnoreCase("promptType")) sp.mPromptType = xpp.getText(); } else if (tagStack.get(tagStack.size() - 2).equalsIgnoreCase("property")) { JSONObject curProperty = properties.lastElement(); // populating the last encountered property if (tagStack.peek().equalsIgnoreCase("key")) curProperty.put("key", xpp.getText()); else if (tagStack.peek().equalsIgnoreCase("label")) curProperty.put("label", xpp.getText()); else if (tagStack.peek().equalsIgnoreCase("value")) curProperty.put("value", xpp.getText()); } } } else if (eventType == XmlPullParser.END_TAG) { tagName = xpp.getName(); tagStack.pop(); if (tagName.equalsIgnoreCase("survey")) { // store the current survey to the database long surveyPID = db.insert(Tables.SURVEYS, null, curSurvey.toCV()); // also store all the prompts we accumulated for it for (SurveyPrompt sp : prompts) { sp.mSurveyID = curSurvey.mSurveyID; sp.mSurveyPID = surveyPID; sp.mCompositeID = curSurvey.mCampaignUrn + ":" + curSurvey.mSurveyID; db.insert(Tables.SURVEY_PROMPTS, null, sp.toCV()); } // flush the prompts we've stored up so far prompts.clear(); // Create Streams here OhmagePDVManager.getInstance().createStreamForSurvey(campaignUrn, curSurvey.mSurveyID); // and clear us from being in any survey curSurvey = null; } else if (tagName.equalsIgnoreCase("prompt")) { SurveyPrompt sp = prompts.lastElement(); // update the current prompt with the collected // properties JSONArray propertyArray = new JSONArray(); for (JSONObject property : properties) propertyArray.put(property); // encode it as json and stuff it in the surveyprompt sp.mProperties = propertyArray.toString(); // and wipe the properties properties.clear(); } } eventType = xpp.next(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } return true; }
From source file:com.fututel.db.DBProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { int matched = URI_MATCHER.match(uri); String matchedTable = null;//w ww.ja va 2 s.c o m Uri baseInsertedUri = null; switch (matched) { case ACCOUNTS: case ACCOUNTS_ID: matchedTable = SipProfile.ACCOUNTS_TABLE_NAME; baseInsertedUri = SipProfile.ACCOUNT_ID_URI_BASE; break; case CALLLOGS: case CALLLOGS_ID: matchedTable = SipManager.CALLLOGS_TABLE_NAME; baseInsertedUri = SipManager.CALLLOG_ID_URI_BASE; break; case FILTERS: case FILTERS_ID: matchedTable = SipManager.FILTERS_TABLE_NAME; baseInsertedUri = SipManager.FILTER_ID_URI_BASE; break; case MESSAGES: case MESSAGES_ID: matchedTable = SipMessage.MESSAGES_TABLE_NAME; baseInsertedUri = SipMessage.MESSAGE_ID_URI_BASE; 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(initialValues); ContentValues cv = ps.getAsContentValue(); cv.put(SipProfileState.ACCOUNT_ID, id); profilesStatus.put(id, cv); Log.d(THIS_FILE, "Added " + cv); } getContext().getContentResolver().notifyChange(uri, null); return uri; default: break; } if (matchedTable == null) { throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); long rowId = db.insert(matchedTable, null, values); // If the insert succeeded, the row ID exists. if (rowId >= 0) { // TODO : for inserted account register it here Uri retUri = ContentUris.withAppendedId(baseInsertedUri, rowId); getContext().getContentResolver().notifyChange(retUri, null); if (matched == ACCOUNTS || matched == ACCOUNTS_ID) { broadcastAccountChange(rowId); } if (matched == CALLLOGS || matched == CALLLOGS_ID) { db.delete(SipManager.CALLLOGS_TABLE_NAME, CallLog.Calls._ID + " IN " + "(SELECT " + CallLog.Calls._ID + " FROM " + SipManager.CALLLOGS_TABLE_NAME + " ORDER BY " + CallLog.Calls.DEFAULT_SORT_ORDER + " LIMIT -1 OFFSET 500)", null); } if (matched == ACCOUNTS_STATUS || matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } return retUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int delete(SQLiteDatabase db, String table) { return db.delete(table, mBuilder.toString(), getArgsArray()); }
From source file:com.sonetel.db.DBProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { int matched = URI_MATCHER.match(uri); String matchedTable = null;//w ww . j ava2 s. co m Uri baseInsertedUri = null; switch (matched) { case ACCOUNTS: case ACCOUNTS_ID: matchedTable = SipProfile.ACCOUNTS_TABLE_NAME; baseInsertedUri = SipProfile.ACCOUNT_ID_URI_BASE; break; case CALLLOGS: case CALLLOGS_ID: matchedTable = SipManager.CALLLOGS_TABLE_NAME; baseInsertedUri = SipManager.CALLLOG_ID_URI_BASE; break; case FILTERS: case FILTERS_ID: matchedTable = SipManager.FILTERS_TABLE_NAME; baseInsertedUri = SipManager.FILTER_ID_URI_BASE; break; case MESSAGES: case MESSAGES_ID: matchedTable = SipMessage.MESSAGES_TABLE_NAME; baseInsertedUri = SipMessage.MESSAGE_ID_URI_BASE; break; case ACCESSNO: matchedTable = SipProfile.ACCESS_NUMS_TABLE_NAME; baseInsertedUri = SipProfile.ACCESS_URI_BASE; 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(initialValues); ContentValues cv = ps.getAsContentValue(); cv.put(SipProfileState.ACCOUNT_ID, id); profilesStatus.put(id, cv); Log.d(THIS_FILE, "Added " + cv); } getContext().getContentResolver().notifyChange(uri, null); return uri; default: break; } if (matchedTable == null) { throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); long rowId = db.insert(matchedTable, null, values); // If the insert succeeded, the row ID exists. if (rowId >= 0) { // TODO : for inserted account register it here Uri retUri = ContentUris.withAppendedId(baseInsertedUri, rowId); getContext().getContentResolver().notifyChange(retUri, null); if (matched == ACCOUNTS || matched == ACCOUNTS_ID) { broadcastAccountChange(rowId); } if (matched == CALLLOGS || matched == CALLLOGS_ID) { db.delete(SipManager.CALLLOGS_TABLE_NAME, CallLog.Calls._ID + " IN " + "(SELECT " + CallLog.Calls._ID + " FROM " + SipManager.CALLLOGS_TABLE_NAME + " ORDER BY " + CallLog.Calls.DEFAULT_SORT_ORDER + " LIMIT -1 OFFSET 500)", null); } if (matched == ACCOUNTS_STATUS || matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } return retUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:edu.cens.loci.provider.LociDbUtils.java
public int deletePlace(long placeId) { final SQLiteDatabase db = mDbHelper.getWritableDatabase(); return db.delete(Tables.PLACES, Places._ID + "=" + String.valueOf(placeId), null); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private int deleteSource(@NonNull final Uri uri, final String selection, final String[] selectionArgs) { // Opens the database object in "write" mode. final SQLiteDatabase db = databaseHelper.getWritableDatabase(); int count;//from w w w. ja v a 2 s.c om // Does the delete based on the incoming URI pattern. switch (MuzeiProvider.uriMatcher.match(uri)) { case SOURCES: // If the incoming pattern matches the general pattern for // sources, does a delete based on the incoming "where" // column and arguments. count = db.delete(MuzeiContract.Sources.TABLE_NAME, selection, selectionArgs); break; case SOURCE_ID: // If the incoming URI matches a single source ID, does the // delete based on the incoming data, but modifies the where // clause to restrict it to the particular source ID. String finalWhere = BaseColumns._ID + " = " + uri.getLastPathSegment(); // If there were additional selection criteria, append them to the final WHERE clause if (selection != null) finalWhere = finalWhere + " AND " + selection; count = db.delete(MuzeiContract.Sources.TABLE_NAME, finalWhere, selectionArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } if (count > 0) { notifyChange(uri); } return count; }