List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public String getName(String buddyId) { int index = buddyId.indexOf('@'); if (index > -1) buddyId = buddyId.substring(0, index); SQLiteDatabase db = mDbHelper.getReadableDatabase(); String where = MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID + "=?"; Cursor c = db.query(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS, new String[] { MessageHistoryContract.ChatEntry.COLUMN_NAME_NAME }, where, new String[] { buddyId }, null, null, null);/*from ww w. j av a 2s .co m*/ c.moveToFirst(); String result = null; if (c.getCount() >= 1) { try { result = c.getString(0); } catch (Exception e) { result = buddyId; } } db.close(); c.close(); // Log.d("MH_DEBUG", result); return result; }
From source file:ru.gkpromtech.exhibition.db.Table.java
public void update(T item, int conflictAlgorithm) { SQLiteDatabase db = mSqlHelper.getWritableDatabase(); try {//from ww w.j a v a2s.c o m db.beginTransaction(); db.updateWithOnConflict(mTableName, itemToRow(item), "id = ?", new String[] { String.valueOf(item.id) }, conflictAlgorithm); db.setTransactionSuccessful(); } catch (Exception e) { e.printStackTrace(); } finally { db.endTransaction(); db.close(); } }
From source file:com.maxwen.wallpaper.board.databases.Database.java
private List<String> getSelectedCategories() { List<String> categories = new ArrayList<>(); SQLiteDatabase db = this.getReadableDatabase(); String column = KEY_SELECTED; Cursor cursor = db.query(TABLE_CATEGORIES, new String[] { KEY_NAME }, column + " = ?", new String[] { "1" }, null, null, KEY_NAME);//from w w w. j av a 2 s .co m if (cursor.moveToFirst()) { do { categories.add(cursor.getString(0)); } while (cursor.moveToNext()); } cursor.close(); db.close(); return categories; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void banThread(String group, String clean_subject, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); // First, check if it already is on the banned_threads table (it could be with unbanned=1) Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_threads " + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject), null); if (c.getCount() > 0) { // Existed c.moveToFirst();/*from ww w. ja v a 2s . c o m*/ dbwrite.execSQL("UPDATE banned_threads SET bandisabled=0 WHERE _id=" + c.getInt(0)); } else { // New troll goes down to the pit ContentValues cv = new ContentValues(); cv.put("subscribed_group_id", groupid); cv.put("bandisabled", 0); cv.put("clean_subject", clean_subject); dbwrite.insert("banned_threads", null, cv); } // Mark all the messages from the thread as read so they get cleaned later dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject)); c.close(); dbwrite.close(); db.close(); }
From source file:com.data.pack.ViewVideo.java
/** * Insert data into table//w ww . ja v a 2s . c o m * * @param String * , String , String , String , String ,String ,String * @return */ private void insertDurationData(String id, String duration) { try { SQLiteDatabase db = placeData.getWritableDatabase(); ContentValues values; values = new ContentValues(); values.put("ID", id); values.put("Duration", duration); db.insert("FitnessWorkoutDuration", null, values); db.close(); } catch (Exception e) { // TODO: handle exception } }
From source file:com.dm.wallpaper.board.databases.Database.java
public void addWallpapers(@NonNull List<Wallpaper> wallpapers) { String query = "INSERT INTO " + TABLE_WALLPAPERS + " (" + KEY_NAME + "," + KEY_AUTHOR + "," + KEY_URL + "," + KEY_THUMB_URL + "," + KEY_CATEGORY + "," + KEY_ADDED_ON + ") VALUES (?,?,?,?,?,?);"; SQLiteDatabase db = this.getWritableDatabase(); SQLiteStatement statement = db.compileStatement(query); db.beginTransaction();/* w w w . j a v a 2 s . co m*/ for (int i = 0; i < wallpapers.size(); i++) { statement.clearBindings(); statement.bindString(1, wallpapers.get(i).getName()); statement.bindString(2, wallpapers.get(i).getAuthor()); statement.bindString(3, wallpapers.get(i).getUrl()); statement.bindString(4, wallpapers.get(i).getThumbUrl()); statement.bindString(5, wallpapers.get(i).getCategory()); statement.bindString(6, TimeHelper.getLongDateTime()); statement.execute(); } db.setTransactionSuccessful(); db.endTransaction(); db.close(); }
From source file:cl.gisred.android.RepartoActivity.java
public void readCountData() { SQLiteDatabase db = sqlReparto.getReadableDatabase(); String[] sValues = { "id", "codigo", "x", "y" }; Cursor cData = db.query("repartos", sValues, null, null, null, null, null, null); if (cData != null && cData.getCount() >= 0) { iContRep = cData.getCount();//w w w . j a va 2s. co m cData.close(); } db.close(); }
From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchActivity.java
private void search(final String language, final String string, final boolean cache) { mFirstPubMedPosition = 0;/*from ww w .j ava 2 s . co m*/ mFirstWebOfSciencePosition = 0; mFirstMedlinePlusPosition = 0; mFirstWikipediaPosition = 0; mFirstUpToDatePosition = 0; mFirstBmjPosition = 0; mFirstNhiPosition = 0; mFirstSmlPosition = 0; mFirstForskningPosition = 0; mFirstHelsebiblioteketPosition = 0; mFirstTidsskriftetPosition = 0; mFirstOncolexPosition = 0; mFirstBrukerhandbokenPosition = 0; mFirstHelsenorgePosition = 0; try { RequestQueue requestQueue = Volley.newRequestQueue(mContext); String apiUri = getString(R.string.project_website_uri) + "api/1/diseases-and-treatments/" + language + "/?search=" + URLEncoder.encode(string, "utf-8"); if (!cache) requestQueue.getCache().remove(apiUri); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { for (int i = 0; i < response.length(); i++) { try { JSONObject jsonObject = response.getJSONObject(i); String type = jsonObject.getString("type"); if (mFirstPubMedPosition == 0 && type.equals("pubmed")) mFirstPubMedPosition = i; if (mFirstWebOfSciencePosition == 0 && type.equals("webofscience")) mFirstWebOfSciencePosition = i; if (mFirstMedlinePlusPosition == 0 && type.equals("medlineplus")) mFirstMedlinePlusPosition = i; if (mFirstWikipediaPosition == 0 && type.equals("wikipedia")) mFirstWikipediaPosition = i; if (mFirstUpToDatePosition == 0 && type.equals("uptodate")) mFirstUpToDatePosition = i; if (mFirstBmjPosition == 0 && type.equals("bmj")) mFirstBmjPosition = i; if (mFirstNhiPosition == 0 && type.equals("nhi")) mFirstNhiPosition = i; if (mFirstSmlPosition == 0 && type.equals("sml")) mFirstSmlPosition = i; if (mFirstForskningPosition == 0 && type.equals("forskning")) mFirstForskningPosition = i; if (mFirstHelsebiblioteketPosition == 0 && type.equals("helsebiblioteket")) mFirstHelsebiblioteketPosition = i; if (mFirstTidsskriftetPosition == 0 && type.equals("tidsskriftet")) mFirstTidsskriftetPosition = i; if (mFirstOncolexPosition == 0 && type.equals("oncolex")) mFirstOncolexPosition = i; if (mFirstBrukerhandbokenPosition == 0 && type.equals("brukerhandboken")) mFirstBrukerhandbokenPosition = i; if (mFirstHelsenorgePosition == 0 && type.equals("helsenorge")) mFirstHelsenorgePosition = i; } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } } mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); if (mTools.isTablet()) mRecyclerView.setLayoutManager( new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); mRecyclerView.setAdapter(new DiseasesAndTreatmentsSearchAdapter(mContext, response, string)); ContentValues contentValues = new ContentValues(); contentValues.put(DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING, string); SQLiteDatabase sqLiteDatabase = new DiseasesAndTreatmentsSQLiteHelper(mContext) .getWritableDatabase(); sqLiteDatabase.delete(DiseasesAndTreatmentsSQLiteHelper.TABLE, DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(string) + " COLLATE NOCASE", null); sqLiteDatabase.insert(DiseasesAndTreatmentsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); mTools.showToast(getString(R.string.diseases_and_treatments_search_could_not_search), 1); Log.e("DiseasesAndTreatments", error.toString()); finish(); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } }
From source file:org.emergent.android.weave.syncadapter.SyncCache.java
public boolean updateLastSync(URI uri, String engineName, Date lastSyncDate) { Log.d(TAG, "SyncCache.updateLastSync()"); if (lastSyncDate == null) { Log.w(TAG, "lastSyncDate was null"); return false; }/* w ww.ja v a 2 s .c o m*/ long lastSync = lastSyncDate.getTime(); SQLiteDatabase db = null; try { String uriStr = uri.toASCIIString(); db = m_helper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(MgColumns.LAST_MODIFIED, lastSync); long updateCount = db.update(META_GLOBAL_TABLE_NAME, values, MgColumns.NODE_URI + " = ? AND " + MgColumns.ENGINE_NAME + " = ?", new String[] { uriStr, engineName }); assert updateCount < 2 : "Should not be able to update more than one row by constraints!"; return updateCount > 0; } finally { if (db != null) try { db.close(); } catch (Exception ignored) { } } }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public void addCategories(List<Category> categories) { SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < categories.size(); i++) { ContentValues values = new ContentValues(); values.put(KEY_NAME, categories.get(i).getName()); values.put(KEY_THUMB_URL, categories.get(i).getThumbUrl()); // new categories are always selected by default values.put(KEY_SELECTED, 1);//from w w w.j a v a 2 s. com db.insert(TABLE_CATEGORIES, null, values); } db.close(); }