Java Code Examples for android.database.sqlite.SQLiteDatabase.isReadOnly()

The following are Jave code examples for showing how to use isReadOnly() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GodotSQL   File: KeyValDatabase.java   View Source Code Vote up 5 votes
@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);
		}
 
Example 2
Project: Phoenix-for-VK   File: DBHelper.java   View Source Code Vote up 5 votes
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}
 
Example 3
Project: Phoenicia   File: DatabaseHelper.java   View Source Code Vote up 5 votes
@Override
public void onOpen(SQLiteDatabase db) {
	super.onOpen(db);

	if (!db.isReadOnly()) {
		// Enable or disable foreign key constraints
		db.execSQL("PRAGMA foreign_keys=" + FOREIGN_KEY_CONSTRAINTS + ";");
	}
}
 
Example 4
Project: android_firebase_green_thumb   File: DbHelper.java   View Source Code Vote up 5 votes
/**
 * Add initial plant data when the app launches for the first time.
 * @param db The database to insert data
 */
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    // Only update the database if it's writable
    if (db.isReadOnly()) {
        return;
    }
    // Only insert initial plant data if the plant database is empty
    Cursor cursor = db.query(PlantEntry.TABLE_NAME, null, null, null, null, null, null);
    if (cursor.moveToFirst()) {
        return;
    }
    cursor.close();

    // Plant database is empty. Add all the plants.
    String[] names = context.getResources().getStringArray(R.array.plant_names);
    String[] descriptions = context.getResources().getStringArray(R.array.plant_descriptions);
    int[] prices = context.getResources().getIntArray(R.array.plant_prices);

    if (names.length != descriptions.length
            && descriptions.length != prices.length) {
        throw new IllegalStateException("There should be an equal number of plant names/descriptions/prices");
    }

    for (int i = 0; i < names.length; i++) {
        ContentValues values = new ContentValues();
        values.put(PlantEntry.COLUMN_NAME, names[i]);
        values.put(PlantEntry.COLUMN_DESCRIPTION, descriptions[i]);
        values.put(PlantEntry.COLUMN_PRICE, prices[i]);
        values.put(PlantEntry.COLUMN_CART_QUANTITY, 0);
        values.put(PlantEntry.COLUMN_PURCHASED_QUANTITY, 0);
        db.insert(PlantEntry.TABLE_NAME, null, values);
    }
    context.getContentResolver().notifyChange(PlantEntry.CONTENT_URI, null);
}
 
Example 5
Project: PokerBankroll   File: DBHelper.java   View Source Code Vote up 5 votes
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);

    if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}
 
Example 6
Project: Cash   File: DBHelper.java   View Source Code Vote up 5 votes
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);

    if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}
 
Example 7
Project: Pocket-Plays-for-Twitch   File: Service.java   View Source Code Vote up 4 votes
private static boolean isDbSafe(SQLiteDatabase db) {
	return db.isOpen() && !db.isReadOnly() && !db.isDbLockedByCurrentThread();
}