List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.dm.wallpaper.board.databases.Database.java
@Nullable public Wallpaper getRandomWallpaper() { Wallpaper wallpaper = null;//from w ww .j av a 2 s . c om List<String> selected = getSelectedCategories(true); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return null; StringBuilder CONDITION = new StringBuilder(); for (String item : selected) { if (CONDITION.length() > 0) { CONDITION.append(" OR ").append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } else { CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } selection.add("%" + item.toLowerCase(Locale.getDefault()) + "%"); } SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(), selection.toArray(new String[selection.size()]), null, null, "RANDOM()", "1"); if (cursor.moveToFirst()) { do { wallpaper = new Wallpaper(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5)); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpaper; }
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public void setOnline(String buddyId, String status) { int index = buddyId.indexOf('@'); if (index >= 0) { buddyId = buddyId.substring(0, index); }/*www. ja va2 s .c o m*/ //Log.d("DATABASE", "Changing OnlineStatus"); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(MessageHistoryContract.ChatEntry.COLUMN_NAME_LAST_ONLINE, status); String whereClause = MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID + " == ?"; db.update(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS, values, whereClause, new String[] { buddyId }); db.close(); }
From source file:com.snt.bt.recon.database.DBHandler.java
public void updateTripEnd(UUID sessionId, String timestamp) { SQLiteDatabase database = this.getWritableDatabase(); String updateQuery = "UPDATE " + TABLE_TRIPS + " set " + KEY_TIMESTAMP_END + " = '" + timestamp + "' where " + KEY_SESSION_ID + "=" + "'" + sessionId + "'"; //Log.d("DatabaseTest", updateQuery); database.execSQL(updateQuery);// ww w . jav a 2 s .c om database.close(); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void deleteFavorites() { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;//from www . j a va2 s.com db.delete(TABLE_FAVORITES, null, null); db.close(); IbikeApplication.setFavoritesFetched(false); }
From source file:github.popeen.dsub.util.SongDBHandler.java
public synchronized Long[] getLastPlayed(int serverKey, String id) { SQLiteDatabase db = this.getReadableDatabase(); String[] columns = { SONGS_LAST_PLAYED, SONGS_LAST_COMPLETED }; Cursor cursor = db.query(TABLE_SONGS, columns, SONGS_SERVER_KEY + " = ? AND " + SONGS_SERVER_ID + " = ?", new String[] { Integer.toString(serverKey), id }, null, null, null, null); try {//from ww w .j ava2 s. co m cursor.moveToFirst(); Long[] dates = new Long[2]; dates[0] = cursor.getLong(0); dates[1] = cursor.getLong(1); return dates; } catch (Exception e) { return null; } finally { db.close(); } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void updateStarredThread(boolean starred, String clean_subject, int groupid, Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbWrite = db.getWritableDatabase(); clean_subject = clean_subject.replace("'", "''"); String query;/*from w w w . j a v a2 s.c om*/ if (starred == false) { query = "DELETE FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject); dbWrite.execSQL(query); } else { // Check that it's not already on the table query = "SELECT _ID FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject); Cursor c = dbWrite.rawQuery(query, null); if (c.getCount() == 0) { ContentValues cv = new ContentValues(); cv.put("subscribed_group_id", groupid); cv.put("clean_subject", clean_subject); dbWrite.insert("starred_threads", null, cv); } c.close(); } dbWrite.close(); db.close(); }
From source file:com.codebutler.farebot.core.DBUtil.java
private boolean hasDatabase() { SQLiteDatabase tempDatabase = null; File file = getDBFile();//from w ww .j av a 2 s . c o m if (!file.exists()) { Log.d(TAG, String.format("Database for %s does not exist, will install version %s", getDBName(), getDesiredVersion())); return false; } try { tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY); int currentVersion = tempDatabase.getVersion(); if (allowGreaterDatabaseVersions() ? currentVersion < getDesiredVersion() : currentVersion != getDesiredVersion()) { Log.d(TAG, String.format("Updating %s database. Old: %s, new: %s", getDBName(), currentVersion, getDesiredVersion())); tempDatabase.close(); tempDatabase = null; } else { Log.d(TAG, String.format("Not updating %s database. Current: %s, app has: %s", getDBName(), currentVersion, getDesiredVersion())); } } catch (SQLiteException ignored) { } if (tempDatabase != null) { tempDatabase.close(); } return (tempDatabase != null); }
From source file:com.openerp.support.calendar.OECalendar.java
/** * Update the status of synced events in crm.meeting table. * //w w w. j a v a2s.c om * @param meeting_id * : record id of the crm.meeting. * @param calendar_id * : under which meeting synced. * @param event_id * : creted event id under calendar. * @param sync * : true, if synced in OpenERP Mobile calendar. */ public void update_SyncedEvent(int meeting_id, String calendar_id, String event_id, String sync) { db = new MeetingDBHelper(context); SQLiteDatabase database = db.getWritableDatabase(); String query = "update " + db.getTableName() + " set in_cal_sync = '" + sync + "',calendar_event_id = '" + event_id + "', calendar_id = '" + calendar_id + "' where id = " + meeting_id; database.execSQL(query); database.close(); }
From source file:com.snt.bt.recon.database.DBHandler.java
public void deleteOldTrips(UUID sessionId) { SQLiteDatabase database = this.getWritableDatabase(); String updateQuery = "DELETE FROM " + TABLE_TRIPS + " where " + KEY_SESSION_ID + "!=" + "'" + sessionId + "' and " + KEY_UPLOAD_STATUS + " != '" + "no" + "'"; //Delete if partial or yes //Log.d("DatabaseTest", updateQuery); database.execSQL(updateQuery);/* w w w . j a va2 s. co m*/ database.close(); }
From source file:com.dm.wallpaper.board.databases.Database.java
public List<Wallpaper> getFavoriteWallpapers() { List<Wallpaper> wallpapers = new ArrayList<>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, null, KEY_FAVORITE + " = ?", new String[] { "1" }, null, null, KEY_ADDED_ON + " DESC, " + KEY_ID); if (cursor.moveToFirst()) { do {/*from w ww. ja v a 2 s . c o m*/ Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getInt(6) == 1); wallpapers.add(wallpaper); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpapers; }