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.granita.tasks.homescreen.TaskListWidgetSettingsActivity.java

private void persistSelectedTaskLists(ArrayList<Long> lists) {
    WidgetConfigurationDatabaseHelper dbHelper = new WidgetConfigurationDatabaseHelper(this);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // delete old configuration
    WidgetConfigurationDatabaseHelper.deleteConfiguration(db, mAppWidgetId);

    // add new configuration
    for (Long taskId : lists) {
        WidgetConfigurationDatabaseHelper.insertTaskList(db, mAppWidgetId, taskId);
    }//from  w  w w .j av a 2s.  c o  m
    db.close();
}

From source file:com.dm.material.dashboard.candybar.databases.Database.java

public boolean isWallpapersEmpty() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, null, null, null, null, null, null);
    int rowCount = cursor.getCount();
    cursor.close();// ww w . j a  v  a 2s .  c o  m
    db.close();
    return rowCount == 0;
}

From source file:eu.rubenrosado.tinypasswordmanager.AllRows.java

public void onClickDelete(View v) {
    DBHelper dbhelper = new DBHelper(this);
    SQLiteDatabase sql = dbhelper.getWritableDatabase();

    int position = lv.getPositionForView(v);

    sql.delete(DBHelper.TABLENAME, DBHelper.COLID + "=" + String.valueOf(spArray.get(position).getId()), null);
    sql.close();
    dbhelper.close();//from www.j  a v  a  2 s. c  o m

    spArray.remove(position);
    decryptedPasswords.remove(position);
    adapter.notifyDataSetChanged();
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static List<MhSpRequest> listLatestRequestsSince(Context context, String trollId, int dayCount) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.HOUR_OF_DAY, dayCount * -24);
    Date sinceDate = instance.getTime();

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(SQL_LIST_REQUESTS_SINCE,
            new String[] { trollId, "" + sinceDate.getTime() });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }//from w ww.  j a va 2 s.  c o  m
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

    cursor.close();
    database.close();

    return result;
}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * Delete a chat room.//from www .j  a va 2s  . co  m
 * @param chatroom
 */
public void deleteChatroom(Chatroom chatroom) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_CHATROOMS, KEY_NAME + " = ?", new String[] { chatroom.getName() });
    db.close();
}

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

public static String[] getSubscribedGroups(Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor cur = dbread.rawQuery("SELECT name FROM subscribed_groups", null);
    int c = cur.getCount();
    String[] subscribed = null;// w  w w.j a v  a 2 s  .  c  om
    if (c > 0) {
        subscribed = new String[c];

        cur.moveToFirst();
        for (int i = 0; i < c; i++) {
            subscribed[i] = cur.getString(0);
            cur.moveToNext();
        }
    }

    cur.close();
    dbread.close();
    db.close();
    return subscribed;
}

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

public static void setAuthorFavorite(boolean isFavorite, boolean mustBeFavorite, String author,
        Context context) {//from   w  w w .  j  a va 2  s  .  c om

    if (isFavorite && mustBeFavorite || !isFavorite && !mustBeFavorite)
        return;

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

    if (isFavorite && !mustBeFavorite) {
        // Remove from the table
        dbwrite.execSQL("DELETE FROM favorite_users WHERE name=" + esc(author));
    } else if (!isFavorite && mustBeFavorite) {
        // Insert into the table
        ContentValues cv = new ContentValues();
        cv.put("name", author);
        dbwrite.insert("favorite_users", null, cv);
    }
    dbwrite.close();
    dbhelper.close();
}

From source file:it.sasabz.android.sasabus.classes.dialogs.SelectFavoritenDialog.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    if (menuItemIndex == 0) {
        Favorit fav = list.get(info.position);
        SQLiteDatabase db = new FavoritenDB(getContext()).getWritableDatabase();
        if (fav.delete(db))
            Log.v("FAVORITENLOESCHEN", "OK");
        else// ww w.  j a v  a2s  .co m
            Log.v("FAVORITENLOESCHEN", "FEHLER");
        db.close();
        list.remove(info.position);
        MyFavoritenListAdapter favoriten = new MyFavoritenListAdapter(SASAbus.getContext(), list);
        ListView liste = (ListView) findViewById(android.R.id.list);
        liste.setAdapter(favoriten);
    }
    return false;
}

From source file:it.sasabz.android.sasabus.classes.dialogs.SelectFavoritenDialog.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    if (menuItemIndex == 0) {
        Favorit fav = list.get(info.position);
        SQLiteDatabase db = new FavoritenDB(getContext()).getWritableDatabase();
        if (fav.delete(db))
            Log.v("FAVORITENLOESCHEN", "OK");
        else//from w w w .j a v a 2  s  .c om
            Log.v("FAVORITENLOESCHEN", "FEHLER");
        db.close();
        list.remove(info.position);
        MyFavoritenListAdapter favoriten = new MyFavoritenListAdapter(SASAbus.getContext(), list);
        ListView liste = (ListView) findViewById(android.R.id.list);
        liste.setAdapter(favoriten);
    }
    return false;
}

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

public static HashSet<String> getFavoriteAuthors(Context context) {

    HashSet<String> favoriteAuthors = null;

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

    Cursor c = dbread.rawQuery("SELECT name FROM favorite_users", null);
    if (c.getCount() > 0) {
        favoriteAuthors = new HashSet<String>(c.getCount());
        c.moveToFirst();// w w w.ja  v  a2  s .c  o m

        int count = c.getCount();
        for (int i = 0; i < count; i++) {
            favoriteAuthors.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (favoriteAuthors == null)
        favoriteAuthors = new HashSet<String>(0);
    return favoriteAuthors;
}