SQLiteDatabase isOpen - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:close, beginTransaction, compileStatement, endTransaction, isOpen
	} 
 
	public DataManager(Context context, boolean useDebugDb) {
		this.context = context;
		this.useDebugDb = useDebugDb;
	} 
 
	private boolean isOpenDb() { 
		return (db != null && db.isOpen());
	} 
 
	private boolean closeDb() { 
		if (isOpenDb()) { 
			try { 
				db.close();
				 
				db = null;
				rpgCharacterDao = null;
				 
				return true; 

7
CodeRank
This code example shows how to use the following methods:close, isOpen, isReadOnly
     * 
     * @throws SQLiteException if the database cannot be opened for writing 
     * @return a read/write database object valid until {@link #close} is called 
     */ 
    public synchronized SQLiteDatabase getWritableDatabase() {
        if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
            return mDatabase;  // The database is already open for business
        } 
 
        if (mIsInitializing) {
            throw new IllegalStateException("getWritableDatabase called recursively");
        } 
 
        // If we have a read-only database open, someone could be using it 
        // (though they shouldn't), which would cause a lock to be held on 
        // the file, and our attempts to open the database read-write would 
        // fail waiting for the file lock.  To prevent that, we acquire the 
        // lock on the read-only database, which shuts out other users. 
 
        boolean success = false;

7
CodeRank
This code example shows how to use the following methods:close, isOpen, isReadOnly
     * 
     * @throws SQLiteException if the database cannot be opened for writing 
     * @return a read/write database object valid until {@link #close} is called 
     */ 
    public synchronized SQLiteDatabase getWritableDatabase() {
        if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
            return mDatabase;  // The database is already open for business
        } 
 
        if (mIsInitializing) {
            throw new IllegalStateException("getWritableDatabase called recursively");
        } 
 
        // If we have a read-only database open, someone could be using it 
        // (though they shouldn't), which would cause a lock to be held on 
        // the file, and our attempts to open the database read-write would 
        // fail waiting for the file lock.  To prevent that, we acquire the 
        // lock on the read-only database, which shuts out other users. 
 
        boolean success = false;

7
CodeRank
This code example shows how to use the following methods:isOpen, isReadOnly, getClass

7
CodeRank
This code example shows how to use the following methods:delete, isOpen
    private SQLiteDatabase mDatabase;
 
    @SuppressWarnings("deprecation") 
    public synchronized SQLiteDatabase getDatabase(Context context) {
        // Always return the cached database, if we've got one 
        if (mDatabase == null || !mDatabase.isOpen()) {
            DatabaseHelper helper = new DatabaseHelper(context, DATABASE_NAME);
            mDatabase = helper.getWritableDatabase();
            if (mDatabase != null) {
                mDatabase.setLockingEnabled(true);
            } 
		} 
 
        return mDatabase;
    } 
 
    private class DatabaseHelper extends SQLiteOpenHelper {
 
        DatabaseHelper(Context context, String name) {
            super(context, name, null, DATABASE_VERSION);

6
CodeRank
This code example shows how to use the following methods:isOpen
        database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
    } 
 
    @Test 
    public void testIsOpen() throws Exception { 
        assertThat(database.isOpen()).isTrue();
        database.close();
        assertThat(database.isOpen()).isFalse();
    } 
 
    @Test 
    public void shouldStoreGreatBigHonkinIntegersCorrectly() throws Exception { 
        database.execSQL("INSERT INTO table_name(big_int) VALUES(1234567890123456789);");
        Cursor cursor = database.query("table_name", new String[]{"big_int"}, null, null, null, null, null);
        cursor.moveToFirst();
        assertEquals(1234567890123456789L, cursor.getLong(0));
    } 
 
    @Test 
    public void testSuccessTransaction() throws Exception { 
6
CodeRank
This code example shows how to use the following methods:close, isOpen, rawQuery, setLocale, setVersion
    	lastCursor=myDataBase.rawQuery(sql, selectionArgs);
    	return lastCursor;
    } 
     
    private void checkDBOpen() { 
    	if(myDataBase!=null && myDataBase.isOpen()) myDataBase.close();
    	if(lastCursor!=null && !lastCursor.isClosed()) lastCursor.close();
	} 
 
	public void execSQL(String sql){
		checkDBOpen(); 
    	openDataBase(); 
    	myDataBase.execSQL(sql);
    	close(); 
    } 
    /* 
    public SQLiteDatabase Instance(){ 
    	return myDataBase; 
    } 
    */ 
6
CodeRank
This code example shows how to use the following methods:close, isOpen
	 */ 
	public synchronized void close() { 
		if (mIsInitializing)
			throw new IllegalStateException("Closed during initialization");
 
		if (mDatabase != null && mDatabase.isOpen()) {
			mDatabase.close();
			mDatabase = null;
		} 
	} 
 
	public File getDatabasePath(String name) {
		String EXTERN_PATH = null;
		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)==true)
		{ 
			EXTERN_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
			+ "/db/"; 
			File f=new File(EXTERN_PATH);
			if(!f.exists())
			{ 
6
CodeRank
This code example shows how to use the following methods:isOpen, query
		schemaVersion = getSchemaVersion();
      mDatabasePath = path;
	} 
	 
	public boolean validDatabase(){ 
		return (mDatabase == null)? false : mDatabase.isOpen();
	} 
 
   public boolean reopenDatabase(){ 
      try { 
         mDatabase = SQLiteDatabase.openDatabase(mDatabasePath,
                 null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
         return (mDatabase != null);
      } 
      catch (Exception e){ return false; }
   } 
	 
	public Cursor getVerses(int sura, int minAyah, int maxAyah){
		return getVerses(sura, minAyah, maxAyah, VERSE_TABLE);
	} 

6
CodeRank
This code example shows how to use the following methods:close, isOpen, isReadOnly
	public synchronized SQLiteDatabase getReadableDatabase() {
		if (useLocal) {
			return super.getReadableDatabase(); 
		} 
 
		if (mDatabase != null && mDatabase.isOpen()) {
			return mDatabase; // The database is already open for business
		} 
 
		if (mIsInitializing) {
			throw new IllegalStateException("getReadableDatabase called recursively");
		} 
 
		try { 
			return getWritableDatabase(); 
		} catch (SQLiteException e) {
			Log.e(TAG, "Couldn't open " + DATABASE_NAME + " for writing (will try read-only):", e);
		} 
 
		SQLiteDatabase db = null;

6
CodeRank

Related SQLiteDatabase isOpen Questions & Answers:

Other SQLiteDatabase isOpen Examples

363:		public void closeDB() {
364:			SQLiteDatabase db = this.getReadableDatabase();
365:			if (db != null && db.isOpen())
366:				db.close();
367:		}

Read More

1:		public void closeDB() {
2:			SQLiteDatabase db = this.getReadableDatabase();
3:			if (db != null && db.isOpen())
4:				db.close();
5:		}

Read More

isOpen Method Overview
Returns true if the database is currently open.
See Code Examples for other Android SQLiteDatabase Methods: