List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void unBanThread(String group, String clean_subject, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); dbwrite.execSQL("DELETE FROM banned_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject));//from w w w . java 2 s. c om dbwrite.close(); db.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void setGroupAllRead(String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwriter = dbhelper.getWritableDatabase(); dbwriter.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE subscribed_group_id=" + groupid); dbwriter.close(); dbhelper.close();/*from w w w . j a va 2 s . c om*/ }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static boolean isAuthorFavorite(String author, Context context) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbread = dbhelper.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id FROM favorite_users WHERE name=" + esc(author), null); boolean res = (c.getCount() > 0); c.close();// w w w .j a v a 2s . co m dbread.close(); dbhelper.close(); return res; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static boolean isGroupSubscribed(String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbread = dbhelper.getReadableDatabase(); Cursor cur = dbread.rawQuery("SELECT _id FROM subscribed_groups WHERE _id=" + groupid, null); boolean ret = (cur.getCount() > 0); cur.close();//from ww w. ja v a2s .c o m dbread.close(); dbhelper.close(); return ret; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void markAsRead(long server_article_number, Context context) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwriter = dbhelper.getWritableDatabase(); dbwriter.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE server_article_number=" + server_article_number); dbwriter.close(); dbhelper.close();//from ww w .j a v a2 s . c o m }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void markAsRead(String msgId, Context context) { if (msgId != null) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwriter = dbhelper.getWritableDatabase(); dbwriter.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE server_article_id=" + esc(msgId)); dbwriter.close(); dbhelper.close();// ww w . j a va 2s . c om } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static int getGroupUnreadCount(String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbread = dbhelper.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id FROM headers WHERE read=0 AND subscribed_group_id=" + groupid, null); int result = c.getCount(); c.close();//w ww . j a v a2 s . co m dbread.close(); dbhelper.close(); return result; }
From source file:com.andreadec.musicplayer.IndexFolderService.java
private void clearSongsDatabase() { SQLiteDatabase db = new SongsDatabase().getWritableDatabase(); db.delete("Songs", "", null); db.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void updateHeaderRecordAttachments(int headerId, Vector<HashMap<String, String>> attachsVector, Context context) {/*from w w w .j a v a 2s . c o m*/ if (attachsVector == null || attachsVector.size() == 0) return; StringBuffer strbu = new StringBuffer(); HashMap<String, String> attachData = null; int len = attachsVector.size(); for (int i = 0; i < len; i++) { attachData = attachsVector.get(i); strbu.append(attachData.get("md5")); if (i != len - 1) strbu.append(";"); } DBHelper db = new DBHelper(context); SQLiteDatabase dbwriter = db.getWritableDatabase(); String q = "UPDATE headers SET has_attachments=1, attachments_fnames=" + esc(strbu.toString()) + " WHERE _id=" + headerId; dbwriter.execSQL(q); dbwriter.close(); db.close(); }
From source file:cd.education.data.collector.android.external.ExternalDataReaderImpl.java
@Override public void doImport(Map<String, File> externalDataMap) { for (Map.Entry<String, File> stringFileEntry : externalDataMap.entrySet()) { String dataSetName = stringFileEntry.getKey(); File dataSetFile = stringFileEntry.getValue(); if (dataSetFile.exists()) { File dbFile = new File(dataSetFile.getParentFile().getAbsolutePath(), dataSetName + ".db"); if (dbFile.exists()) { // this means the someone updated the csv file, so we need to reload it boolean deleted = dbFile.delete(); if (!deleted) { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " has changed but we could not delete the previous DB at " + dbFile.getAbsolutePath()); continue; }/*from w w w . j a v a 2 s . c o m*/ } ExternalSQLiteOpenHelper externalSQLiteOpenHelper = new ExternalSQLiteOpenHelper(dbFile); externalSQLiteOpenHelper.importFromCSV(dataSetFile, this, formLoaderTask); if (formLoaderTask.isCancelled()) { Log.w(ExternalDataUtil.LOGGER_NAME, "The import was cancelled, so we need to rollback."); // we need to drop the database file since it might be partially populated. It will be re-created next time. Log.w(ExternalDataUtil.LOGGER_NAME, "Closing database to be deleted " + dbFile); // then close the database SQLiteDatabase db = externalSQLiteOpenHelper.getReadableDatabase(); db.close(); // the physically delete the db. try { FileUtils.forceDelete(dbFile); Log.w(ExternalDataUtil.LOGGER_NAME, "Deleted " + dbFile.getName()); } catch (IOException e) { Log.e(ExternalDataUtil.LOGGER_NAME, e.getMessage(), e); } // then just exit and do not process any other CSVs. return; } else { // rename the dataSetFile into "dataSetFile.csv.imported" in order not to be loaded again File importedFile = new File(dataSetFile.getParentFile(), dataSetFile.getName() + ".imported"); boolean renamed = dataSetFile.renameTo(importedFile); if (!renamed) { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " could not be renamed to be archived. It will be re-imported again! :("); } else { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " was renamed to " + importedFile.getName()); } } } } }