List of usage examples for android.database.sqlite SQLiteDatabase delete
public int delete(String table, String whereClause, String[] whereArgs)
From source file:com.appsimobile.appsii.module.apps.AppsProvider.java
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;// ww w .ja va2s . c o m int match = sURLMatcher.match(uri); switch (match) { case TABLE_APPS_ITEM: { String id = uri.getLastPathSegment(); count = db.delete(args.table, "_id=" + id, args.args); break; } case TABLE_APPS: { count = db.delete(args.table, args.where, args.args); break; } case TABLE_TAGS_ITEM: { String id = uri.getLastPathSegment(); count = db.delete(args.table, "_id=" + id, args.args); break; } case TABLE_TAGS: { count = db.delete(args.table, args.where, args.args); break; } case TABLE_HISTORY_ITEM: { String id = uri.getLastPathSegment(); count = db.delete(args.table, "_id=" + id, args.args); break; } case TABLE_HISTORY: { count = db.delete(args.table, args.where, args.args); break; } default: { throw new IllegalArgumentException("Unknown URL " + uri); } } if (count > 0) { sendNotify(uri); } return count; }
From source file:net.olejon.mdapp.PoisoningsCardsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();/*from www .j a va 2s. co m*/ return; } // Intent final Intent intent = getIntent(); searchString = intent.getStringExtra("search"); // Layout setContentView(R.layout.activity_poisonings_cards); // Toolbar mToolbar = (Toolbar) findViewById(R.id.poisonings_cards_toolbar); mToolbar.setTitle(getString(R.string.poisonings_cards_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.poisonings_cards_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.poisonings_cards_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.poisonings_cards_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new PoisoningsCardsAdapter(mContext, new JSONArray())); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // No poisonings mNoPoisoningsLayout = (LinearLayout) findViewById(R.id.poisonings_cards_no_poisonings); Button noPoisoningsHelsenorgeButton = (Button) findViewById(R.id.poisonings_cards_check_on_helsenorge); Button noPoisoningsHelsebiblioteketButton = (Button) findViewById( R.id.poisonings_cards_check_on_helsebiblioteket); noPoisoningsHelsenorgeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.poisonings_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "https://helsenorge.no/sok/giftinformasjon/?k=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8")); mContext.startActivity(intent); } catch (Exception e) { Log.e("PoisoningsCardsActivity", Log.getStackTraceString(e)); } } }); noPoisoningsHelsebiblioteketButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.poisonings_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "http://www.helsebiblioteket.no/forgiftninger/alle-anbefalinger?cx=005475784484624053973%3A3bnj2dj_uei&ie=UTF-8&q=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&sa=S%C3%B8k"); mContext.startActivity(intent); } catch (Exception e) { Log.e("PoisoningsCardsActivity", Log.getStackTraceString(e)); } } }); // Search search(searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put(PoisoningsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new PoisoningsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(PoisoningsSQLiteHelper.TABLE, PoisoningsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(PoisoningsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle(getString(R.string.poisonings_cards_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); mNoPoisoningsLayout.setVisibility(View.GONE); mSwipeRefreshLayout.setVisibility(View.VISIBLE); search(correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("PoisoningsCardsActivity", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("PoisoningsCardsActivity", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("PoisoningsCardsActivity", Log.getStackTraceString(e)); } }
From source file:com.wheelermarine.publicAccessSites.Updater.java
@Override protected Integer doInBackground(URL... urls) { try {/*from w w w. j av a2 s. c om*/ final DatabaseHelper db = new DatabaseHelper(context); SQLiteDatabase database = db.getWritableDatabase(); if (database == null) throw new IllegalStateException("Unable to open database!"); database.beginTransaction(); try { // Clear out the old data. database.delete(DatabaseHelper.PublicAccessEntry.TABLE_NAME, null, null); // Connect to the web server and locate the FTP download link. Log.v(TAG, "Finding update: " + urls[0]); activity.runOnUiThread(new Runnable() { @Override public void run() { progress.setMessage("Locating update..."); progress.setIndeterminate(true); } }); Document doc = Jsoup.connect(urls[0].toString()).timeout(timeout * 1000).userAgent(userAgent).get(); URL dataURL = null; for (Element element : doc.select("a")) { if (element.hasAttr("href") && element.attr("href").endsWith(".zip")) { dataURL = new URL(element.attr("href")); } } // Make sure the download URL was fund. if (dataURL == null) throw new FileNotFoundException("Unable to locate data URL."); // Connect to the FTP server and download the update. Log.v(TAG, "Downloading update: " + dataURL); activity.runOnUiThread(new Runnable() { @Override public void run() { progress.setMessage("Downloading update..."); progress.setIndeterminate(true); } }); HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(dataURL.toString()); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); if (entity == null) throw new IOException("Error downloading update."); Map<Integer, Location> locations = null; // Download the ZIP archive. Log.v(TAG, "Downloading: " + dataURL.getFile()); InputStream in = entity.getContent(); if (in == null) throw new FileNotFoundException(dataURL.getFile() + " was not found!"); try { ZipInputStream zin = new ZipInputStream(in); try { // Locate the .dbf entry in the ZIP archive. ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { if (entry.getName().endsWith(entryName)) { readDBaseFile(zin, database); } else if (entry.getName().endsWith(shapeEntryName)) { locations = readShapeFile(zin); } } } finally { try { zin.close(); } catch (Exception e) { // Ignore this error. } } } finally { in.close(); } if (locations != null) { final int recordCount = locations.size(); activity.runOnUiThread(new Runnable() { @Override public void run() { progress.setIndeterminate(false); progress.setMessage("Updating locations..."); progress.setMax(recordCount); } }); int progress = 0; for (int recordNumber : locations.keySet()) { PublicAccess access = db.getPublicAccessByRecordNumber(recordNumber); Location loc = locations.get(recordNumber); access.setLatitude(loc.getLatitude()); access.setLongitude(loc.getLongitude()); db.updatePublicAccess(access); publishProgress(++progress); } } database.setTransactionSuccessful(); return db.getPublicAccessesCount(); } finally { database.endTransaction(); } } catch (Exception e) { error = e; Log.e(TAG, "Error loading data: " + e.getLocalizedMessage(), e); return -1; } }
From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java
public void deleteBudgetOneEntry(long id) { SQLiteDatabase db = db(); Budget b = load(Budget.class, id); writeDeleteLog(BUDGET_TABLE, b.remoteKey); db.delete(BUDGET_TABLE, "_id=?", new String[] { String.valueOf(id) }); }
From source file:ru.gkpromtech.exhibition.db.Table.java
public void delete(SQLiteDatabase db, int id) { db.delete(mTableName, "id = ?", new String[] { String.valueOf(id) }); }
From source file:project.cs.netinfservice.database.IODatabase.java
/** * Deletes the information object corresponding to the specified hash value from the database. * /*from ww w . j ava 2 s . co m*/ * @param hash * The hash value identifying the information object. */ public void deleteIO(String hash) { Log.d(TAG, "Deleting an information object from the database."); try { SQLiteDatabase db = getWritableDatabase(); // Finds and deletes object db.delete(TABLE_IO, KEY_HASH + " = ?", new String[] { hash }); db.close(); } catch (SQLiteException e) { Log.e(TAG, "Failed deleting information object. " + "Error occured due to an unexpected database problem."); } }
From source file:com.google.zxing.client.android.history.HistoryManager.java
public void deleteHistoryItem(int number) { SQLiteOpenHelper helper = new DBHelper(activity); SQLiteDatabase db = null; Cursor cursor = null;// w w w. j a v a 2s . com try { db = helper.getWritableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); cursor.move(number); db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null); } finally { close(cursor, db); } }
From source file:com.android.leanlauncher.WidgetPreviewLoader.java
private void clearDb() { SQLiteDatabase db = mDb.getWritableDatabase(); // Delete everything try {//ww w . ja v a2 s. c o m db.delete(CacheDb.TABLE_NAME, null, null); } catch (SQLiteDiskIOException e) { } catch (SQLiteCantOpenDatabaseException e) { throw e; } }
From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java
public void deleteBudget(long id) { SQLiteDatabase db = db(); Budget b = load(Budget.class, id); writeDeleteLog(BUDGET_TABLE, b.remoteKey); db.delete(BUDGET_TABLE, "_id=?", new String[] { String.valueOf(id) }); String sql = "select remote_key from " + BUDGET_TABLE + " where parent_budget_id=" + id + ""; Cursor cursorCursor = db.rawQuery(sql, null); if (cursorCursor.moveToFirst()) { do {// ww w . j a v a2s . co m String rKey = cursorCursor.getString(0); writeDeleteLog(BUDGET_TABLE, rKey); } while (cursorCursor.moveToNext()); } cursorCursor.close(); db.delete(BUDGET_TABLE, "parent_budget_id=?", new String[] { String.valueOf(id) }); }
From source file:org.qeo.android.service.ApplicationSecurity.java
/** * Insert allowed readers/writers into the database. Clear the mReadersWriters map when everything is saved in the * database.//from w w w.jav a2s . co m */ private synchronized void insertReadersWriters() { SQLiteDatabase db = mService.getDatabase(); // first delete all known readers/writers for this uid to ensure old ones get removed String where = TableManifestRW.C_UID + "=?"; db.delete(TableManifestRW.NAME, where, new String[] { Integer.toString(mUid) }); // add all for (Map.Entry<String, RW> entry : mReadersWriters.entrySet()) { ContentValues values = new ContentValues(); values.put(TableManifestRW.C_NAME, entry.getKey()); values.put(TableManifestRW.C_UID, mUid); values.put(TableManifestRW.C_PKG_NAME, mPkgName); LOG.fine("Add rw to table: " + entry.getKey() + " -- " + mUid + " -- " + mPkgName); switch (entry.getValue()) { case R: // read only values.put(TableManifestRW.C_READ, 1); values.put(TableManifestRW.C_WRITE, 0); break; case W: // write only values.put(TableManifestRW.C_READ, 0); values.put(TableManifestRW.C_WRITE, 1); break; case RW: // read/write only values.put(TableManifestRW.C_READ, 1); values.put(TableManifestRW.C_WRITE, 1); break; default: throw new IllegalStateException("value not handled"); } db.insertOrThrow(TableManifestRW.NAME, null, values); } mReadersWriters.clear(); }