本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.isReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.isReadOnly方法的具体用法?Java SQLiteDatabase.isReadOnly怎么用?Java SQLiteDatabase.isReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.isReadOnly方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@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);
}
示例2: onOpen
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
示例3: onOpen
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@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 + ";");
}
}
示例4: onOpen
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* 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);
}
示例5: onOpen
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
示例6: isDbSafe
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private static boolean isDbSafe(SQLiteDatabase db) {
return db.isOpen() && !db.isReadOnly() && !db.isDbLockedByCurrentThread();
}