Example usage for android.database.sqlite SQLiteDatabase close

List of usage examples for android.database.sqlite SQLiteDatabase close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase close.

Prototype

public void close() 

Source Link

Document

Releases a reference to the object, closing the object if the last reference was released.

Usage

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void setMessageCatched(long id, boolean catched, Context context) {

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getReadableDatabase();

    int numbool;//from w w w .  j  ava2 s. co  m

    if (catched)
        numbool = 1;
    else
        numbool = 0;

    dbwrite.execSQL("UPDATE headers SET catched=" + numbool + " WHERE _id=" + id);
    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static boolean groupHasUncatchedMessages(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT _id FROM headers WHERE subscribed_group_id=" + groupid + " AND read=0 AND catched=0";
    Cursor c = dbread.rawQuery(q, null);

    int count = c.getCount();

    c.close();//w  w w. j  a  va2 s.  c  o  m
    dbread.close();
    db.close();

    return (count > 0);
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

/**
 * Unsubscribe a group, deleting from the DB the headers and from the disk the group's directory storage 
 * for bodies and attachments.//  ww  w.  j a v  a  2s  .c  o  m
 * 
 */
public static void unsubscribeGroup(String group, Context context) {

    int groupid = getGroupIdFromName(group, context);

    if (groupid == -1)
        return;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbWrite = db.getWritableDatabase();

    String query = "DELETE FROM subscribed_groups WHERE _ID=" + groupid;
    dbWrite.execSQL(query);
    query = "DELETE FROM headers WHERE subscribed_group_id=" + groupid;
    dbWrite.execSQL(query);
    dbWrite.close();
    db.close();

    FSUtils.deleteDirectory(
            UsenetConstants.EXTERNALSTORAGE + "/" + UsenetConstants.APPNAME + "/offlinecache/groups/" + group);

    FSUtils.deleteDirectory(UsenetConstants.EXTERNALSTORAGE + "/" + UsenetConstants.APPNAME + "/"
            + UsenetConstants.ATTACHMENTSDIR + "/" + group);
}

From source file:org.egov.android.data.SQLiteHelper.java

public void initialize() {
    SQLiteDatabase db = getReadableDatabase();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void subscribeGroup(String group, Context context) {

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbwrite = dbhelper.getWritableDatabase();

    ContentValues cv = new ContentValues();
    cv.put("profile_id", 1);
    cv.put("name", group);
    cv.put("lastFetched", -1);
    cv.put("unread_count", -1);
    dbwrite.insert("subscribed_groups", null, cv);

    dbwrite.close();
    dbhelper.close();/*  ww w  . j  a  va2 s  .  c o  m*/
}

From source file:org.egov.android.data.SQLiteHelper.java

public void execSQL(String sql) {
    SQLiteDatabase db = getWritableDatabase();
    db.execSQL(sql);
    db.close();
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Truncate table//from   ww  w .  j a va  2s  .  co m
 * 
 * @param tableName
 */

public void truncate(String tableName) {
    SQLiteDatabase db = getWritableDatabase();
    db.delete(tableName, null, null);
    db.close();
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Insert data into table//from   www  . ja v  a  2  s  .  co  m
 * 
 * @param tableName
 * @param ContentValues
 */

public long insert(String tableName, ContentValues cv) {
    SQLiteDatabase db = getWritableDatabase();
    long result = db.insert(tableName, null, cv);
    db.close();
    return result;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static long getGroupLastFetchedNumber(String group, Context context) {

    long lastFetched = -1;

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase readdb = dbhelper.getReadableDatabase();

    String fQuery = "SELECT lastFetched FROM subscribed_groups WHERE name=" + esc(group);
    Cursor cur = readdb.rawQuery(fQuery, null);

    if (cur.getCount() > 0) {
        cur.moveToFirst();//from ww  w.  j  av a  2 s.c o  m
        lastFetched = cur.getInt(0);
    }

    cur.close();
    readdb.close();
    dbhelper.close();

    return lastFetched;
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Delete data from table// ww  w .j a va  2 s  .  c o m
 * 
 * @param tableName
 * @param whereClause
 * @param whereArgs
 */

public int delete(String tableName, String whereClause, String[] whereArgs) {
    SQLiteDatabase db = getWritableDatabase();
    int result = db.delete(tableName, whereClause, whereArgs);
    db.close();
    return result;
}