android.database.sqlite.SQLiteDatabase#isReadOnly ( )源码实例Demo

下面列出了android.database.sqlite.SQLiteDatabase#isReadOnly ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: callmeter   文件: DataProvider.java
/**
 * Run RuleMatcher.unmatch locally.
 *
 * @param db {@link SQLiteDatabase}
 */
private static void unmatch(final SQLiteDatabase db) {
    Log.d(TAG, "unmatch()");
    if (db.isReadOnly()) {
        Log.e(TAG, "Database is readonly, can not unmatch on upgrade!");
        return;
    }
    ContentValues cv = new ContentValues();
    cv.put(DataProvider.Logs.PLAN_ID, DataProvider.NO_ID);
    cv.put(DataProvider.Logs.RULE_ID, DataProvider.NO_ID);
    // reset all but manually set plans
    db.update(DataProvider.Logs.TABLE, cv, DataProvider.Logs.RULE_ID + " is null or NOT ("
            + DataProvider.Logs.RULE_ID + " = " + DataProvider.NOT_FOUND + " AND "
            + DataProvider.Logs.PLAN_ID + " != " + DataProvider.NOT_FOUND + ")", null);
    cv.clear();
    cv.put(DataProvider.Plans.NEXT_ALERT, 0);
    db.update(DataProvider.Plans.TABLE, cv, null, null);
}
 
源代码2 项目: GodotSQL   文件: KeyValDatabase.java
@Override
		public void onCreate(SQLiteDatabase sqLiteDatabase) {
			if (!sqLiteDatabase.isReadOnly()){
			sqLiteDatabase.execSQL("PRAGMA foreign_key=ON");
			}

//			sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " +
//			KEYVAL_TABLE_NAME + "(" + KEYVAL_COLUMN_KEY + " TEXT PRIMARY KEY, " +
//			KEYVAL_COLUMN_VAL + " TEXT)");

			sqLiteDatabase.execSQL(CREATE_TABLE_KEYVAL);
		}
 
源代码3 项目: QuantumFlux   文件: QuantumFluxDatabase.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onConfigure(SQLiteDatabase db) {
    super.onConfigure(db);
    if (!db.isReadOnly()) {
        db.enableWriteAheadLogging();
    }
}
 
源代码4 项目: Material-Movies   文件: DbHelper.java
@Override
public void onCreate(SQLiteDatabase db) {
    if (db.isReadOnly()) {
        db = getWritableDatabase();
    }
    db.execSQL(DbConstants.Movies.CREATE_SQL);
}
 
源代码5 项目: CPOrm   文件: CPOrmDatabase.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onConfigure(SQLiteDatabase db) {

    super.onConfigure(db);
    if (!db.isReadOnly()) {
        db.enableWriteAheadLogging();
    }
}
 
源代码6 项目: NoiseCapture   文件: Storage.java
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    if (!db.isReadOnly()) {
        // Enable foreign key constraints
        db.execSQL(ACTIVATE_FOREIGN_KEY);
    }
}
 
源代码7 项目: Beats   文件: LocalyticsProvider.java
@Override
public void onOpen(final SQLiteDatabase db)
{
    super.onOpen(db);

    if (Constants.IS_LOGGABLE)
    {
        Log.v(Constants.LOG_TAG, String.format("SQLite library version is: %s", DatabaseUtils.stringForQuery(db, "select sqlite_version()", null))); //$NON-NLS-1$//$NON-NLS-2$
    }

    if (!db.isReadOnly())
    {
        /*
         * Enable foreign key support
         */
        db.execSQL("PRAGMA foreign_keys = ON;"); //$NON-NLS-1$

        // if (Constants.IS_LOGGABLE)
        // {
        // try
        // {
        //                        final String result1 = DatabaseUtils.stringForQuery(db, "PRAGMA foreign_keys;", null); //$NON-NLS-1$
        //                        Log.v(Constants.LOG_TAG, String.format("Foreign keys support result was: %s", result1)); //$NON-NLS-1$
        // }
        // catch (final SQLiteDoneException e)
        // {
        // Log.w(Constants.LOG_TAG, e);
        // }
        // }
    }
}
 
源代码8 项目: ExtensionsPack   文件: LocalyticsProvider.java
@Override
public void onOpen(final SQLiteDatabase db)
{
    super.onOpen(db);

    if (Constants.IS_LOGGABLE)
    {
        Log.v(Constants.LOG_TAG, String.format("SQLite library version is: %s", DatabaseUtils.stringForQuery(db, "select sqlite_version()", null))); //$NON-NLS-1$//$NON-NLS-2$
    }

    if (!db.isReadOnly())
    {
        /*
         * Enable foreign key support
         */
        db.execSQL("PRAGMA foreign_keys = ON;"); //$NON-NLS-1$

        // if (Constants.IS_LOGGABLE)
        // {
        // try
        // {
        //                        final String result1 = DatabaseUtils.stringForQuery(db, "PRAGMA foreign_keys;", null); //$NON-NLS-1$
        //                        Log.v(Constants.LOG_TAG, String.format("Foreign keys support result was: %s", result1)); //$NON-NLS-1$
        // }
        // catch (final SQLiteDoneException e)
        // {
        // Log.w(Constants.LOG_TAG, e);
        // }
        // }
    }
}
 
源代码9 项目: WiFiAfterConnect   文件: WifiAuthDatabase.java
@Override
public void onOpen(SQLiteDatabase db) {
	super.onOpen(db);
	if (!db.isReadOnly()) {
        // Enable foreign key constraints
        db.execSQL("PRAGMA foreign_keys=ON;");
    }		
}
 
源代码10 项目: sniffer154   文件: PacketDatabaseHelper.java
@Override
public void onOpen(SQLiteDatabase db) {
	super.onOpen(db);
	if (!db.isReadOnly()) {
		// Enable foreign key constraints
		db.execSQL("PRAGMA foreign_keys=ON;");
	}
}
 
源代码11 项目: Onosendai   文件: DbAdapter.java
@Override
public void onOpen (final SQLiteDatabase db) {
	super.onOpen(db);
	if (!db.isReadOnly()) {
		db.execSQL("PRAGMA foreign_keys=ON;");
		this.log.i("foreign_keys=ON");
	}
}
 
源代码12 项目: Twire   文件: Service.java
private static boolean isDbSafe(SQLiteDatabase db) {
    return db.isOpen() && !db.isReadOnly() && !db.isDbLockedByCurrentThread();
}
 
源代码13 项目: Pocket-Plays-for-Twitch   文件: Service.java
private static boolean isDbSafe(SQLiteDatabase db) {
    return db.isOpen() && !db.isReadOnly() && !db.isDbLockedByCurrentThread();
}
 
源代码14 项目: android-sdcard-helper   文件: SQLiteSDCardHelper.java
private SQLiteDatabase getDatabaseLocked(boolean writable){
    if (mDatabase != null) {
        if (!mDatabase.isOpen()) {
            // Darn!  The user closed the database by calling mDatabase.close().
            mDatabase = null;
        } else if (!writable || !mDatabase.isReadOnly()) {
            // The database is already open for business.
            return mDatabase;
        }
    }

    if (mIsInitializing) {
        throw new IllegalStateException("getDatabase 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.

    SQLiteDatabase db = mDatabase;
    try {
        mIsInitializing = true;

        if (db != null) {
            //close  read-only databases, create a new writable
            if (writable && db.isReadOnly()) {
                db.close();
            }
        }

        try {
            db = openDatabase(SQLiteDatabase.OPEN_READWRITE);
        } catch (SQLiteException e) {
            // Couldn't open the DB, let's try to create it.
            Log.e(TAG, "Couldn't open " + mName
                    + " for writing (will try read-only):", e);
            // Here if we fail, we propagate the exception to our user.
            db = openDatabase(SQLiteDatabase.OPEN_READONLY);
        }

        onConfigure(db);

        final int version = db.getVersion();
        if (version != mNewVersion) {
            if (db.isReadOnly()) {
                throw new SQLiteException("Can't upgrade read-only database from version " +
                        db.getVersion() + " to " + mNewVersion + ": " + mName);
            }

            db.beginTransaction();
            try {
                if (version == 0) {
                    onCreate(db);
                } else {
                    if (version > mNewVersion) {
                        onDowngrade(db, version, mNewVersion);
                    } else {
                        onUpgrade(db, version, mNewVersion);
                    }
                }
                db.setVersion(mNewVersion);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

        onOpen(db);

        if (db.isReadOnly()) {
            Log.w(TAG, "Opened " + mName + " in read-only mode");
        }

        mDatabase = db;
        return db;
    }finally {
        mIsInitializing = false;
        if (db != null && db != mDatabase) {
            db.close();
        }
    }
}
 
源代码15 项目: NoiseCapture   文件: Storage.java
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Upgrade queries
    // Do not use static table and column names
    if(oldVersion == 1) {
        // Upgrade from 1 to version 2
        // Add record length attribute
        if (!db.isReadOnly()) {
            db.execSQL("ALTER TABLE record ADD COLUMN time_length INTEGER");
        }
        oldVersion = 2;
    }
    if(oldVersion == 2) {
        // Add gps speed and bearing attribute
        if (!db.isReadOnly()) {
            db.execSQL("ALTER TABLE leq ADD COLUMN speed FLOAT");
            db.execSQL("ALTER TABLE leq ADD COLUMN bearing FLOAT");
        }
        oldVersion = 3;
    }
    if(oldVersion == 3) {
        if(db.isReadOnly()) {
            // New feature, user input
            db.execSQL("ALTER TABLE leq ADD COLUMN description TEXT");
            db.execSQL("ALTER TABLE leq ADD COLUMN pleasantness SMALLINT DEFAULT 2");
            db.execSQL("ALTER TABLE leq ADD COLUMN photo_miniature BLOB");
            db.execSQL("ALTER TABLE leq ADD COLUMN photo_uri TEXT");
            db.execSQL( "CREATE TABLE record_tag(tag_id INTEGER PRIMARY KEY, record_id INTEGER, " +
                        "PRIMARY KEY(tag_id, record_id) " +
                        "FOREIGN KEY(record_id) REFERENCES  record(record_id) ON DELETE CASCADE);");
        }
        oldVersion = 4;
    }
    if(oldVersion == 4) {
        db.execSQL("ALTER TABLE record_tag ADD COLUMN tag_system_name TEXT");
        oldVersion = 5;
    }
    if(oldVersion == 5) {
        // Copy content to new table
        db.execSQL("ALTER TABLE record rename to record_old;");
        db.execSQL( "CREATE TABLE record(record_id INTEGER PRIMARY KEY, record_utc LONG," +
                " upload_id TEXT, leq_mean FLOAT, time_length INTEGER, description TEXT," +
                " photo_uri TEXT, pleasantness SMALLINT DEFAULT 2);");
        db.execSQL("INSERT INTO record SELECT record_id , record_utc ,upload_id , leq_mean ," +
                " time_length , description ,photo_uri , pleasantness from record_old;");
        db.execSQL("DROP TABLE IF EXISTS record_old;");
        oldVersion = 6;
    }
    if(oldVersion == 6) {
        if (!db.isReadOnly()) {
            db.execSQL("ALTER TABLE record ADD COLUMN calibration_gain FLOAT DEFAULT 0");
        }
        oldVersion = 7;
    }
    if(oldVersion == 7) {
        if(!db.isReadOnly()) {
            // Up to version 7, there was a swapping of speed and bearing
            db.execSQL("UPDATE leq SET bearing=speed, speed=bearing;");
        }
        oldVersion = 8;
    }
    if(oldVersion == 8) {
        if(!db.isReadOnly()) {
            db.execSQL("ALTER TABLE record add column "+Record.COLUMN_NOISEPARTY_TAG + " TEXT");
        }
        oldVersion = 9;
    }
}
 
源代码16 项目: q-municate-android   文件: DbHelperUtils.java
public static void onOpen(SQLiteDatabase db) {
    if (!db.isReadOnly()) {
        // Enable foreign key constraints
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}
 
源代码17 项目: q-municate-android   文件: DbHelperUtils.java
public static void onOpen(SQLiteDatabase db) {
    if (!db.isReadOnly()) {
        // Enable foreign key constraints
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}