SQLiteDatabase isReadOnly - 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 isReadOnly method.

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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isOpen, isReadOnly, getClass

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:beginTransaction, endTransaction, execSQL, isReadOnly, setTransactionSuccessful
 
	@Override 
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		 
		if(!db.isReadOnly()){
 
			// create table 
	        db.execSQL("create table if not exists bookmark("
        		+"_id integer primary key AUTOINCREMENT" 
        		+",uri text" 
        		+",lno int" 
        		+",fname text" 
        		+",caption text" 
        		+",ctime int" 
	        +")"); 
	         
			// create table 
	        db.execSQL("create table if not exists tmpdir("
        		+"_id integer primary key AUTOINCREMENT" 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getVersion, isOpen, isReadOnly
  
		if (dbExist) {
			if (LOGV) Log.v(TAG, "Found existing DB at " + dbFile);
 
			mDB = SQLiteDatabase.openDatabase(dbFile, null, SQLiteDatabase.OPEN_READONLY);
			int thisDBVersion = mDB.getVersion();
			mDB.close();
			 
			if (LOGV) Log.v(TAG, "Current DB Version: v" + thisDBVersion + " - Shipped DB Version is v" + DATABASE_VERSION);
			if (thisDBVersion != DATABASE_VERSION) {							
				try { 
					copyDB(dbFile);
				} catch (IOException e) {
					throw new Error("Error copying database");
				} 
			}	 
		} 
		else { 
			if (LOGV) Log.v(TAG, "Creating a new DB at " + dbFile);
			// By calling this method and empty database will be created into the default system path 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, isOpen, isReadOnly
     */ 
    public synchronized SQLiteDatabase getWritableDatabase() {
    	if (mHelper != null) {
    		return mHelper.getWritableDatabase();
    	} 
        if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
            return mDatabase;  // The database is already open for business
        } 
        boolean success = false;
        SQLiteDatabase db = null;
        try { 
            db = SQLiteDatabase.openOrCreateDatabase(mName, null);
 
            int version = db.getVersion();
            if (version != mNewVersion) {
                db.beginTransaction();
                try { 
                    if (version == 0) {
                        onCreate(db);
                    } else { 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
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;

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, isOpen, isReadOnly, rawQuery
	 * @param openDb True if the database needs to be opened. 
	 * @return True if tableName exists in the database. 
	 */ 
	public boolean tableExists(String tableName, boolean openDb) {
	    if(openDb) {
	        if(myDataBase == null || !myDataBase.isOpen()) {
	            myDataBase = getReadableDatabase();
	        } 
 
	        if(!myDataBase.isReadOnly()) {
	            myDataBase.close();
	            myDataBase = getReadableDatabase();
	        } 
	    } 
 
	    Cursor cursor = myDataBase.rawQuery("SELECT DISTINCT tbl_name FROM " +
	    		"sqlite_master WHERE tbl_name = '" + tableName + "'", null);
	    if(cursor != null) {
	        if(cursor.getCount() > 0) {
	            cursor.close();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isOpen, isReadOnly
				return insertFieldType(uri, values);
			case FIELD:
				return insertField(uri, values);
			case FORM:
				return insertForm(uri, values);
			case FORMDATA_ID:
				return insertFormData(uri, values);
				// other stuffs not implemented for insertion yet. 
 
			default: 
				throw new IllegalArgumentException("Unknown URI " + uri);
 
		} 
	} 
 
	private Uri insertFormData(Uri uri, ContentValues values) {
		// sanity check, see if the table exists 
		String formid = uri.getPathSegments().get(1);
		String formprefix = ModelTranslator.getFormById(Integer.valueOf(formid).intValue()).getPrefix();
		// SQLiteDatabase dbr = mOpenHelper.getReadableDatabase(); 
5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related SQLiteDatabase isReadOnly Questions & Answers:

isReadOnly Method Overview
Returns true if the database is opened as read only.
See Code Examples for other Android SQLiteDatabase Methods: