SQLiteOpenHelper close - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteOpenHelper close method.

This code example shows how to use the following methods:close, getWritableDatabase
     * @param helper 
     * @return writable database or null if it failed to create/open 
     */ 
    protected SQLiteDatabase getWritable(SQLiteOpenHelper helper) {
        try { 
            return helper.getWritableDatabase();
        } catch (SQLiteException e1) {
            // Make second attempt 
            try { 
                return helper.getWritableDatabase();
            } catch (SQLiteException e2) {
                return null; 
            } 
        } 
    } 
 
    /** 
     * Get readable database 
     * 
     * @param helper 

8
CodeRank
This code example shows how to use the following methods:close
    } 
 
    @SuppressLint("NewApi") 
    @Override 
    public void shutdown() { 
        mDatabaseHelper.close();
 
        super.shutdown(); 
    } 
 
    public static class MyDatabaseHelper extends SQLiteOpenHelper {
        public static final int DATABASE_VERSION = 1;
        public static final String DATABASE_NAME = "tests.db";
        public static final String CREATE_TABLE_SQL = "CREATE TABLE tests(" + BaseColumns._ID +" INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL)";
        public static final String DROP_TABLE_SQL = "DROP TABLE tests;";
 
        public MyDatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            Log.v(TAG, "construct");
        } 
6
CodeRank
This code example shows how to use the following methods:close
                DataProviderContract.DATE_TABLE_NAME); 
    } 
 
    // Closes the SQLite database helper class, to avoid memory leaks 
    public void close() { 
        mHelper.close();
    } 
     
    /** 
     * Defines a helper class that opens the SQLite database for this provider when a request is 
     * received. If the database doesn't yet exist, the helper creates it. 
     */ 
    private class DataProviderHelper extends SQLiteOpenHelper {
        /** 
         * Instantiates a new SQLite database using the supplied database name and version 
         * 
         * @param context The current context 
         */ 
        DataProviderHelper(Context context) {
            super(context,
6
CodeRank
This code example shows how to use the following methods:close
    } 
 
    @Override 
    public void tearDown() { 
        if (mDbHelper != null) {
            mDbHelper.close();
            mDbHelper = null;
            mCalendarCache = null;
        } 
    } 
 
    public void testGenerateCacheException() { 
        boolean hasException = false;
        try { 
            String value = mCalendarCache.readData(null);
        } catch (CalendarCache.CacheException e) {
            hasException = true;
        } 
        assertTrue(hasException);
    } 
5
CodeRank
This code example shows how to use the following methods:close
        _openHelper = createSQLiteOpenHelper(_openHelperContext);
    } 
 
    @Override 
    protected void tearDown() throws Exception { 
        _openHelper.close();
        super.tearDown(); 
    } 
 
    /** 
     * @return Returns the actual SQLiteOpenHelper under test. 
     */ 
    public T getSQLiteOpenHelper() { 
        return _openHelper;
    } 
 
    protected T createSQLiteOpenHelper(Context context) throws Exception {
        return _openHelperClass.getConstructor(Context.class)
                               .newInstance(_openHelperContext);
    } 
5
CodeRank
This code example shows how to use the following methods:close
    } 
 
    @Override 
    public void tearDown() { 
        if (mDbHelper != null) {
            mDbHelper.close();
            mDbHelper = null;
            mCalendarCache = null;
        } 
    } 
 
    public void testGenerateCacheException() { 
        boolean hasException = false;
        try { 
            String value = mCalendarCache.readData(null);
        } catch (CalendarCache.CacheException e) {
            hasException = true;
        } 
        assertTrue(hasException);
    } 
5
CodeRank
This code example shows how to use the following methods:close
        if (mDatabase != null && mDatabase.isOpen()) {
            mDatabase.close();
            mDatabase = null;
        } 
        if (mHelper != null) {
        	mHelper.close();
        } 
    } 
 
    public abstract void onCreate(SQLiteDatabase db);
    public abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion);
 
} 
5
CodeRank
This code example shows how to use the following methods:close
    	if(count == 0) log("update missed");    	
    } 
     
    public void closeDb(){ 
    	mWritableDb.close();
    	mHelper.close();
    } 
	 
	protected void log(String msg){
		Log.d("AccessDb", msg);
	} 
	 
	public class LocusHelper extends SQLiteOpenHelper {
 
		private Context mContext;
		 
		public LocusHelper(Context context, String name, CursorFactory factory,int version) {
			super(context, name, factory, version);
			mContext = context;
		} 
4
CodeRank
This code example shows how to use the following methods:close
 
	public synchronized void close() { 
		openCount--;
		if (openCount <= 0) {
			openCount = 0;
			helper.close();
		} 
	} 
 
	public Cursor getAllLogs() {
		return db.query(TABLE_NAME, COLUMNS, null, null, null, null, TIMESTAMP + " DESC");
	} 
 
	public Cursor getAllLogsForPackageName(String packageName) {
		return db.query(TABLE_NAME, COLUMNS, PACKAGE_NAME + " = ?", new String[] { packageName }, null, null, TIMESTAMP + " DESC");
	} 
 
	public Cursor getLogsGroupedByPackageName(String packageName) {
		return db.query(TABLE_NAME, COLUMNS, PACKAGE_NAME + " = ?", new String[] { packageName }, TITLE, null, TIMESTAMP + " DESC");
	} 
4
CodeRank
This code example shows how to use the following methods:close
    mDb = mOpenHelper.getWritableDatabase();
    return this;
  } 
 
  public void close() { 
    mOpenHelper.close();
  } 
   
  /** 
   * Create a new project using the name provided. If the project is 
   * successfully created return the new projectId, otherwise return 
   * a -1 to indicate failure. 
   *  
   * @param name the project name 
   * @return projectId or -1 if failed 
   */ 
  public long createProject(String name) {
      ContentValues initialValues = new ContentValues();
      initialValues.put(KEY_NAME, name);
      return mDb.insert(TABLE_NAME, null, initialValues);
4
CodeRank

Related SQLiteOpenHelper close Questions & Answers:

close Method Overview
Close any open database object.
See Code Examples for other Android SQLiteOpenHelper Methods: