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 restartAllGroupsMessages(Context context) {

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

    dbwrite.execSQL("DELETE FROM headers");
    dbwrite.execSQL("UPDATE subscribed_groups SET lastFetched=-1, unread_count=0");
    FSUtils.deleteDirectory(//from  w  w w  . java  2 s .c  o  m
            UsenetConstants.EXTERNALSTORAGE + "/" + UsenetConstants.APPNAME + "/offlinecache/groups");
    FSUtils.deleteDirectory(UsenetConstants.EXTERNALSTORAGE + "/" + UsenetConstants.APPNAME + "/"
            + UsenetConstants.ATTACHMENTSDIR);
    dbwrite.close();
    db.close();
}

From source file:com.elixsr.portforwarder.ui.preferences.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    forwardingManager = ForwardingManager.getInstance();
    localBroadcastManager = LocalBroadcastManager.getInstance(getActivity().getBaseContext());

    // Get tracker.
    tracker = ((FwdApplication) getActivity().getApplication()).getDefaultTracker();

    clearRulesButton = (Preference) findPreference(getString(R.string.pref_clear_rules));

    clearRulesButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override// w w  w .j a v a  2 s. c  o m
        public boolean onPreferenceClick(Preference preference) {
            //code for what you want it to do

            new AlertDialog.Builder(getActivity()).setTitle("Delete all Rules")
                    .setMessage("Are you sure you want to delete all rules?")
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            // set up the database
                            SQLiteDatabase db = new RuleDbHelper(getActivity()).getReadableDatabase();

                            db.delete(RuleContract.RuleEntry.TABLE_NAME, null, null);

                            db.close();

                            clearRulesButton.setEnabled(false);

                            // Build and send an Event.
                            tracker.send(new HitBuilders.EventBuilder().setCategory(CATEGORY_RULES)
                                    .setAction(ACTION_DELETE).setLabel(LABEL_DELETE_RULE).build());

                            Toast.makeText(getActivity(), CLEAR_RULES_COMPLETE_MESSAGE, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // do nothing
                        }
                    }).show();
            return true;
        }
    });

    versionNamePreference = (Preference) findPreference(getString(R.string.pref_version));

    // set up click of help button - show webview
    //        Preference helpButton = (Preference) findPreference(getString(R.string.pref_help_link));
    //        helpButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
    //            @Override
    //            public boolean onPreferenceClick(Preference preference) {
    //                //code for what you want it to do
    //                Intent helpActivityIntent = new Intent(getActivity(), HelpActivity.class);
    //                startActivity(helpActivityIntent);
    //                return true;
    //            }
    //        });

    // set up click of about elixsr button - show webview
    Preference aboutElixsrButton = (Preference) findPreference(getString(R.string.pref_about_link));
    aboutElixsrButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            //code for what you want it to do
            Intent aboutActivityIntent = new Intent(getActivity(), AboutElixsrActivity.class);
            startActivity(aboutActivityIntent);
            return true;
        }
    });

    changeThemeToggle = (Preference) findPreference(getString(R.string.pref_dark_theme));

}

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

public void setWallpaperAddedOn(String url, String date) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_ADDED_ON, date);/*from  w w w. j a va  2 s  . c o m*/
    db.update(TABLE_WALLPAPERS, values, KEY_URL + " = ?", new String[] { url });
    db.close();
}

From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java

public void deleteCookie(String key) {
    SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READWRITE);
    if (db == null)
        return;//from  ww  w .ja  va  2s  .  com
    try {
        db.delete(TABLE_NAME, COLUMNS[COL_NAME] + "=?", new String[] { key });
    } catch (SQLiteException ex) {
        Log.w(TAG, "Error deleting cookie: " + key, ex);
    } finally {
        db.close();
    }
}

From source file:com.digicorp.plugin.sqlitePlugin.SQLitePlugin.java

/**
 * Close a database./*from w  w w  . j a va 2  s .c o m*/
 *
 * @param dbName
 *            The name of the database-NOT including its extension.
 *
 */
private void closeDatabase(String dbName) {
    SQLiteDatabase mydb = this.getDatabase(dbName);

    if (mydb != null) {
        mydb.close();
        this.dbmap.remove(dbName);
    }
}

From source file:com.clutch.ClutchStats.java

private void logABData(JSONObject data) {
    SQLiteDatabase db = getWritableDatabase();
    Object[] args = { ClutchUtils.getUUID(), System.currentTimeMillis() / 1000.0, data.toString() };
    db.execSQL("INSERT INTO ablog (uuid, ts, data) VALUES (?, ?, ?)", args);
    db.close();
}

From source file:com.example.google.touroflondon.data.TourDbHelper.java

/**
 * Extract Route data from a {@link JSONArray} of save it in the database.
 * /*  ww  w  . jav  a 2s . c  o  m*/
 * @param data
 */
public void loadRoute(JSONArray data) throws JSONException {

    SQLiteDatabase db = this.getWritableDatabase();

    // Empty the route table to remove all existing data
    db.delete(TourContract.RouteEntry.TABLE_NAME, null, null);

    // Need to complete transaction first to clear data
    db.close();

    // Begin the insert transaction
    db = this.getWritableDatabase();
    db.beginTransaction();

    // Loop over each location in array
    for (int i = 0; i < data.length(); i++) {
        // extract data
        JSONObject poi = data.getJSONObject(i);
        final double lat = poi.getDouble("lat");
        final double lng = poi.getDouble("lng");

        // Construct insert statement
        ContentValues cv = new ContentValues();
        cv.put(TourContract.RouteEntry.COLUMN_NAME_LAT, lat);
        cv.put(TourContract.RouteEntry.COLUMN_NAME_LNG, lng);

        // Insert data
        db.insert(TourContract.RouteEntry.TABLE_NAME, null, cv);
    }

    if (db != null) {
        // All insert statement have been submitted, mark transaction as
        // successful
        db.setTransactionSuccessful();
        db.endTransaction();
    }
}

From source file:com.melchor629.musicote.MainActivity.java

@Override
public void onLoaded() {
    DB mDbHelper = new DB(getBaseContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    cursordb(db);//from w w  w  .j  av a  2s.c  o  m
    db.close();
    swipeRefreshLayout.setRefreshing(false);
}

From source file:com.example.android.touroflondon.data.TourDbHelper.java

/**
 * Extract Route data from a {@link JSONArray} of save it in the database.
 *
 * @param data/*from ww w .  ja  v a  2  s  . c o m*/
 */
public void loadRoute(JSONArray data) throws JSONException {

    SQLiteDatabase db = this.getWritableDatabase();

    // Empty the route table to remove all existing data
    db.delete(TourContract.RouteEntry.TABLE_NAME, null, null);

    // Need to complete transaction first to clear data
    db.close();

    // Begin the insert transaction
    db = this.getWritableDatabase();
    db.beginTransaction();

    // Loop over each location in array
    for (int i = 0; i < data.length(); i++) {
        // extract data
        JSONObject poi = data.getJSONObject(i);
        final double lat = poi.getDouble("lat");
        final double lng = poi.getDouble("lng");

        // Construct insert statement
        ContentValues cv = new ContentValues();
        cv.put(TourContract.RouteEntry.COLUMN_NAME_LAT, lat);
        cv.put(TourContract.RouteEntry.COLUMN_NAME_LNG, lng);

        // Insert data
        db.insert(TourContract.RouteEntry.TABLE_NAME, null, cv);
    }

    if (db != null) {
        // All insert statement have been submitted, mark transaction as successful
        db.setTransactionSuccessful();
        db.endTransaction();
    }
}

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

public static Vector<Long> getUnreadNoncatchedArticleList(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    Vector<Long> artList = null;
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

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

    int count = c.getCount();
    artList = new Vector<Long>(count);

    c.moveToFirst();// w w  w  .  j  av a  2s  .co  m

    for (int i = 0; i < count; i++) {
        artList.add(c.getLong(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();
    return artList;
}