List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public void removeMessages(String buddyId, long... _ID) { SQLiteDatabase db = mDbHelper.getWritableDatabase(); for (long id : _ID) { db.delete(buddyId, MessageHistoryContract.MessageEntry._ID + "=?", new String[] { String.valueOf(id) }); }/*from ww w.j av a2 s .c om*/ db.close(); }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
public SparseArrayCompat<Wallpaper> getWallpaperAddedOn() { SparseArrayCompat<Wallpaper> dates = new SparseArrayCompat<>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, new String[] { KEY_URL, KEY_ADDED_ON }, null, null, null, null, null);/* w ww.j a v a2 s . c o m*/ if (cursor.moveToFirst()) { do { Wallpaper item = new Wallpaper(cursor.getString(0), cursor.getString(1)); dates.append(dates.size(), item); } while (cursor.moveToNext()); } cursor.close(); db.close(); return dates; }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
public Wallpaper getRandomWallpaper() { Wallpaper wallpaper = null;//from w w w.j a v a2s.c o m SQLiteDatabase db = this.getReadableDatabase(); String query = "SELECT * FROM " + TABLE_WALLPAPERS + " ORDER BY RANDOM() LIMIT 1"; Cursor cursor = db.rawQuery(query, null); if (cursor.moveToFirst()) { do { wallpaper = new Wallpaper(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4)); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpaper; }
From source file:edu.uillinois.wseemann.uicombatschedule.MainActivity.java
private String getDateInfo(Date date) { String strDate = null;/* www .ja va 2s .co m*/ String info = null; Calendar cal = Calendar.getInstance(); cal.setTime(date); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int year = cal.get(Calendar.YEAR); String stringDate = month + "/" + day + "/" + year; Database database = new Database(MainActivity.this); SQLiteDatabase db = database.getReadableDatabase(); Cursor cursor = db.query(Database.DATES_TABLE_NAME, null, Database.DATE + " = ?", new String[] { stringDate }, null, null, null); if (cursor.moveToNext()) { strDate = cursor.getString(cursor.getColumnIndex(Database.DATE)); info = cursor.getString(cursor.getColumnIndex(Database.INFO)); } cursor.close(); db.close(); database.close(); return info; }
From source file:com.rareventure.gps2.GTG.java
/** * Creates an initializes a db (including creating a user data encrypting key. Crypt in preferences must be already set up. * Database is closed after being initialized *///from w w w .j a v a 2s . co m public static void createAndInitializeNewDbFile() { //we create it as a temp file and then move it over so we are sure it //is initialized and ready before we start using it (in case we crash // part way through) File dbTmpFile = GpsTrailerDbProvider.getDbFile(true); SQLiteDatabase newDb = GpsTrailerDbProvider.createNewDbFile(dbTmpFile); GpsTrailerCrypt.generateAndInitializeNewUserDataEncryptingKey(GTG.MASTER_APP_ID, newDb); newDb.close(); dbTmpFile.renameTo(GpsTrailerDbProvider.getDbFile(false)); }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
public SparseArrayCompat<Request> getPremiumRequest() { SparseArrayCompat<Request> requests = new SparseArrayCompat<>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_PREMIUM_REQUEST, null, null, null, null, null, null); if (cursor.moveToFirst()) { do {// ww w .ja va 2s. com Request request = new Request(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4)); requests.append(requests.size(), request); } while (cursor.moveToNext()); } cursor.close(); db.close(); return requests; }
From source file:android.database.DatabaseUtils.java
/** * Creates a db and populates it with the sql statements in sqlStatements. * * @param context the context to use to create the db * @param dbName the name of the db to create * @param dbVersion the version to set on the db * @param sqlStatements the statements to use to populate the db. This should be a single string * of the form returned by sqlite3's <tt>.dump</tt> command (statements separated by * semicolons)/*from w w w .ja v a2 s. c o m*/ */ static public void createDbFromSqlStatements(Context context, String dbName, int dbVersion, String sqlStatements) { SQLiteDatabase db = context.openOrCreateDatabase(dbName, 0, null); // TODO: this is not quite safe since it assumes that all semicolons at the end of a line // terminate statements. It is possible that a text field contains ;\n. We will have to fix // this if that turns out to be a problem. String[] statements = TextUtils.split(sqlStatements, ";\n"); for (String statement : statements) { if (TextUtils.isEmpty(statement)) continue; db.execSQL(statement); } db.setVersion(dbVersion); db.close(); }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
public void addAllWallpapers(WallpaperJSON wallpaper) { SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < wallpaper.getWalls.size(); i++) { ContentValues values = new ContentValues(); values.put(KEY_NAME, wallpaper.getWalls.get(i).name); values.put(KEY_AUTHOR, wallpaper.getWalls.get(i).author); values.put(KEY_URL, wallpaper.getWalls.get(i).url); values.put(KEY_THUMB_URL, wallpaper.getWalls.get(i).thumbUrl); db.insert(TABLE_WALLPAPERS, null, values); }/*w w w . j a v a 2 s.c om*/ db.close(); }
From source file:org.emergent.android.weave.syncadapter.SyncCache.java
public void clear() { SQLiteDatabase db = null; try {//w w w . j a v a 2 s . com db = m_helper.getWritableDatabase(); int count = db.delete(KEY_HASH_TABLE_NAME, null, null); Log.d(TAG, "SyncCacheKeyManager.clear() : count = " + count); } finally { if (db != null) try { db.close(); } catch (Exception ignored) { } } }
From source file:com.cuddlesoft.nori.database.APISettingsDatabase.java
/** * Get all {@link SearchClient.Settings} objects from the database. * * @return List of pairs mapping database IDs to {@link SearchClient.Settings} objects. *//*w w w . j a v a 2s . c o m*/ public List<Pair<Integer, SearchClient.Settings>> getAll() { // Query the database. SQLiteDatabase db = getReadableDatabase(); Cursor c = db.query(TABLE_NAME, null, null, null, null, null, COLUMN_ID); // Convert database Cursor to List. final List<Pair<Integer, SearchClient.Settings>> settingsList = new ArrayList<>(c.getCount()); while (c.moveToNext()) { settingsList.add(new Pair<>(c.getInt(c.getColumnIndex(COLUMN_ID)), cursorToSearchClientSettings(c))); } // Clean up native resources. c.close(); db.close(); return settingsList; }