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.shalzz.attendance.DatabaseHandler.java

/**
 * Delete all tables and create them again
 * *//*w  w w .  j a  v a  2s . co  m*/
public void resetTables() {
    SQLiteDatabase db = this.getWritableDatabase();
    // Delete All Rows
    db.delete(Subject.TABLE_NAME, "1", null);
    db.delete(Period.TABLE_NAME, "1", null);
    db.delete(User.TABLE_NAME, "1", null);
    db.delete(AbsentDate.TABLE_NAME, "1", null);
    db.close();
}

From source file:com.koushikdutta.superuser.PolicyFragmentInternal.java

void load() {
    clear();//from   w  ww  .j a  v a 2s . c  om
    final ArrayList<UidPolicy> policies = SuDatabaseHelper.getPolicies(getActivity());

    SQLiteDatabase db = new SuperuserDatabaseHelper(getActivity()).getReadableDatabase();
    try {
        for (UidPolicy up : policies) {
            int last = 0;
            ArrayList<LogEntry> logs = SuperuserDatabaseHelper.getLogs(db, up, 1);
            if (logs.size() > 0)
                last = logs.get(0).date;
            addPolicy(up, last);
        }
    } finally {
        db.close();
    }
}

From source file:github.popeen.dsub.util.SongDBHandler.java

public synchronized void addSongs(int instance, List<MusicDirectory.Entry> entries) {
    SQLiteDatabase db = this.getWritableDatabase();

    List<Pair<String, String>> pairs = new ArrayList<>();
    for (MusicDirectory.Entry entry : entries) {
        pairs.add(new Pair<>(entry.getId(), FileUtil.getSongFile(context, entry).getAbsolutePath()));
    }/*  w ww  .j av  a 2  s  .  com*/
    addSongs(db, instance, pairs);

    db.close();
}

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

public static Hashtable<String, Object> getHeaderRecordCatchedData(String group, long serverMsgNum,
        Context context) {/* ww  w.  j a  va  2  s .  co m*/
    int groupid = getGroupIdFromName(group, context);

    Hashtable<String, Object> result = null;

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

    Cursor c = dbread.rawQuery("SELECT _id, server_article_id, catched FROM headers WHERE subscribed_group_id="
            + groupid + " AND server_article_number=" + serverMsgNum, null);

    if (c.getCount() == 1) {
        c.moveToFirst();

        result = new Hashtable<String, Object>(3);
        result.put("id", c.getInt(0));
        result.put("server_article_id", c.getString(1));
        if (c.getInt(2) == 1)
            result.put("catched", true);
        else
            result.put("catched", false);
    }

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

    return result;
}

From source file:com.codebutler.farebot.transit.ovc.OVChipDBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = new File(DB_PATH, DB_NAME);
    if (!file.exists()) {
        return false;
    }//from w ww  .ja  v  a2s.  co m

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating OVChip database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:com.example.ryutasakamoto.readfelica.util.DBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = getDBFile();/*from  ww w  .j av a  2 s  .  c  o  m*/
    if (!file.exists()) {
        return false;
    }

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating Suica database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:com.codebutler.farebot.card.felica.DBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = new File(DB_PATH, DB_NAME);
    if (!file.exists()) {
        return false;
    }// w ww. j  a  va  2 s.com

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating Suica database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:com.itime.team.itime.fragments.SettingsFragment.java

private void updateUserTable() {
    UserTableHelper dbHelper = new UserTableHelper(getContext(), "userbase1");
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    ContentValues values = new ContentValues();
    values.put("remember", false);
    db.update("itime_user", values, "id=?", new String[] { "1" });
    dbHelper.close();//from w  w  w.ja v a  2 s .co m
    db.close();
}

From source file:net.olejon.spotcommander.AddComputerActivity.java

private void addComputer() {
    final EditText computerNameInput = (EditText) findViewById(R.id.add_computer_name);
    final EditText computerUriInput = (EditText) findViewById(R.id.add_computer_uri);
    final EditText computerUsernameInput = (EditText) findViewById(R.id.add_computer_username);
    final EditText computerPasswordInput = (EditText) findViewById(R.id.add_computer_password);

    computerNameInput.addTextChangedListener(new TextWatcher() {
        @Override//from   w ww. ja  v  a 2s .com
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            mAddComputerNameInputLayout.setError(null);
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    computerUriInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            mAddComputerUriInputLayout.setError(null);
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    final String computerName = computerNameInput.getText().toString().trim();
    final String computerUri = computerUriInput.getText().toString().trim();
    final String computerUsername = computerUsernameInput.getText().toString().trim();
    final String computerPassword = computerPasswordInput.getText().toString().trim();

    final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
            Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(computerNameInput.getWindowToken(),
            InputMethodManager.HIDE_IMPLICIT_ONLY);

    if (mNetworkScanTask != null && mNetworkScanTask.getStatus() == AsyncTask.Status.RUNNING) {
        mTools.showToast(getString(R.string.add_computer_scanning_network), 0);
    } else if (computerName.equals("")) {
        mAddComputerNameInputLayout.setError(getString(R.string.add_computer_invalid_name));
    } else if (!computerUri.matches("^https?://.*")) {
        mAddComputerUriInputLayout.setError(getString(R.string.add_computer_invalid_uri));
    } else {
        final ContentValues contentValues = new ContentValues();

        contentValues.put(MainSQLiteHelper.COLUMN_NAME, computerName);
        contentValues.put(MainSQLiteHelper.COLUMN_URI, computerUri);
        contentValues.put(MainSQLiteHelper.COLUMN_USERNAME, computerUsername);
        contentValues.put(MainSQLiteHelper.COLUMN_PASSWORD, computerPassword);
        contentValues.put(MainSQLiteHelper.COLUMN_NETWORK_NAME, "");
        contentValues.put(MainSQLiteHelper.COLUMN_NETWORK_DEFAULT, 0);

        final SQLiteDatabase database = new MainSQLiteHelper(mContext).getWritableDatabase();

        database.insert(MainSQLiteHelper.TABLE_COMPUTERS, null, contentValues);

        database.close();

        finish();
    }
}

From source file:com.cuddlesoft.nori.database.APISettingsDatabase.java

/**
 * Get single instance of {@link SearchClient.Settings} from the database.
 *
 * @param id Row ID./*  w  w  w .  j a v  a 2s . com*/
 * @return Search client settings object. Null if given ID does not exist in the database.
 */
public SearchClient.Settings get(long id) {
    // Query the database.
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.query(TABLE_NAME, null, COLUMN_ID + " = ?", new String[] { Long.toString(id) }, null, null,
            COLUMN_ID, "1");

    // Prepare return value.
    final SearchClient.Settings settings = (!c.moveToNext()) ? null : cursorToSearchClientSettings(c);

    // Clean up native resources.
    c.close();
    db.close();

    return settings;
}