android.content.Context.openOrCreateDatabase()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中android.content.Context.openOrCreateDatabase()方法的一些代码示例,展示了Context.openOrCreateDatabase()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.openOrCreateDatabase()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:openOrCreateDatabase

Context.openOrCreateDatabase介绍

暂无

代码示例

代码示例来源:origin: TommyLemon/APIJSON

public CityDB(Context context, String path) {
  db = context.openOrCreateDatabase(path, Context.MODE_PRIVATE, null);
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

public CityDB(Context context, String path) {
  db = context.openOrCreateDatabase(path, Context.MODE_PRIVATE, null);
}

代码示例来源:origin: oasisfeng/condom

@Override public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
  return mBase.openOrCreateDatabase(name, mode, factory);
}

代码示例来源:origin: oasisfeng/condom

@RequiresApi(HONEYCOMB) @Override public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory,
    DatabaseErrorHandler errorHandler) {
  return mBase.openOrCreateDatabase(name, mode, factory, errorHandler);
}

代码示例来源:origin: k9mail/k-9

private void doOpenOrCreateDb(final File databaseFile) {
  if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
    // internal storage
    mDb = context.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE,
        null);
  } else {
    // external storage
    mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
  }
}

代码示例来源:origin: stackoverflow.com

db = context.openOrCreateDatabase(DATABASE_NAME,
    SQLiteDatabase.CREATE_IF_NECESSARY, null);

代码示例来源:origin: k9mail/k-9

private SQLiteDatabase openDB() {
  SQLiteDatabase db = context.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
  db.beginTransaction();
  try {
    if (db.getVersion() < 1) {
      createStorageDatabase(db);
    } else {
      StorageMigrations.upgradeDatabase(db, migrationsHelper);
    }
    db.setVersion(DB_VERSION);
    db.setTransactionSuccessful();
  } finally {
    db.endTransaction();
  }
  if (db.getVersion() != DB_VERSION) {
    throw new RuntimeException("Storage database upgrade failed!");
  }
  return db;
}

代码示例来源:origin: greenrobot/greenDAO

/** May be overriden by sub classes to set up a different db. */
protected Database createDatabase() {
  SQLiteDatabase sqLiteDatabase;
  if (inMemory) {
    sqLiteDatabase = SQLiteDatabase.create(null);
  } else {
    getContext().deleteDatabase(DB_NAME);
    sqLiteDatabase = getContext().openOrCreateDatabase(DB_NAME, 0, null);
  }
  return new StandardDatabase(sqLiteDatabase);
}

代码示例来源:origin: ankidroid/Anki-Android

/** Open the meta-db */
private static void openDB(Context context) {
  try {
    mMetaDb = context.openOrCreateDatabase(DATABASE_NAME, 0, null);
    if (mMetaDb.needUpgrade(DATABASE_VERSION)) {
      mMetaDb = upgradeDB(mMetaDb, DATABASE_VERSION);
    }
    Timber.v("Opening MetaDB");
  } catch (Exception e) {
    Timber.e(e, "Error opening MetaDB ");
  }
}

代码示例来源:origin: greenrobot/greenDAO

@Override
protected Database createDatabase() {
  int MODE_ENABLE_WRITE_AHEAD_LOGGING = 8;
  getContext().deleteDatabase(DB_NAME);
  SQLiteDatabase sqLiteDatabase = getContext().openOrCreateDatabase(DB_NAME, MODE_ENABLE_WRITE_AHEAD_LOGGING, null);
  return new StandardDatabase(sqLiteDatabase);
}

代码示例来源:origin: Trumeet/MiPushFramework

@Override public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
  return mBase.openOrCreateDatabase(name, mode, factory);
}

代码示例来源:origin: Trumeet/MiPushFramework

@RequiresApi(HONEYCOMB) @Override public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory,
    DatabaseErrorHandler errorHandler) {
  return mBase.openOrCreateDatabase(name, mode, factory, errorHandler);
}

代码示例来源:origin: stackoverflow.com

public EzberletDB(Context context) {
  super(context, DATABASE_NAME,null,DATABASE_VERSION);
  this.context=context;
  SQLiteDatabase db = getWritableDatabase();
  db.close();
  try {
    context.openOrCreateDatabase(DATABASE_NAME, context.MODE_PRIVATE, null); 
  } catch (Exception e) {

    context.openOrCreateDatabase(DATABASE_NAME,context.MODE_PRIVATE,null);
  }
}

代码示例来源:origin: stackoverflow.com

public DatabaseHelper(Context aContext)
{

  sqlDB = aContext.openOrCreateDatabase(DatabaseName, SQLiteDatabase.CREATE_IF_NECESSARY, null);

  OpenHelper openHelper = new OpenHelper(aContext, sqlDB);

  sqlDB = openHelper.getWritableDatabase();
}

代码示例来源:origin: stackoverflow.com

public static final boolean webViewIsProbablyCorrupt(Context context) {
  try {
    SQLiteDatabase cacheDb = context.openOrCreateDatabase("webviewCache.db", 0, null);

    if (cacheDb != null) {
      cacheDb.close();
      return false;
    }
  } catch (Throwable t) {
    Log.w(TAG, t);
  }

  return true;
}

代码示例来源:origin: maskarade/Android-Orma

@NonNull
@Override
public Database provideOnDiskDatabase(@NonNull Context context, @NonNull String name, int mode) {
  return new DefaultDatabase(context.openOrCreateDatabase(name, mode, null, null));
}

代码示例来源:origin: Rachel-Ding/Android-Tiny-Projects

@Override
public boolean onCreate() {
  //设置数据库
  database = getContext().openOrCreateDatabase("mycp.db3", Context.MODE_PRIVATE,null);
  //注:(文件名,只能被当前类调用,...)
  // 为数据库创建一个数据表
  database.execSQL("create table tab( id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL)");
  //注:(tab(id 自增变量,name 是text型非空的)
  return true;
}

代码示例来源:origin: de.greenrobot/greendao

/** May be overriden by sub classes to set up a different db. */
protected SQLiteDatabase createDatabase() {
  if (inMemory) {
    return SQLiteDatabase.create(null);
  } else {
    getContext().deleteDatabase(DB_NAME);
    return getContext().openOrCreateDatabase(DB_NAME, 0, null);
  }
}

代码示例来源:origin: org.greenrobot/greendao

/** May be overriden by sub classes to set up a different db. */
protected Database createDatabase() {
  SQLiteDatabase sqLiteDatabase;
  if (inMemory) {
    sqLiteDatabase = SQLiteDatabase.create(null);
  } else {
    getContext().deleteDatabase(DB_NAME);
    sqLiteDatabase = getContext().openOrCreateDatabase(DB_NAME, 0, null);
  }
  return new StandardDatabase(sqLiteDatabase);
}

代码示例来源:origin: novoda/sqlite-provider

private void createDatabase(String createSqlStatements) {
    createDbFromSqlStatements(getContext(), DB_NAME, 1, createSqlStatements);
    SQLiteDatabase db = getContext().openOrCreateDatabase(DB_NAME, 0, null);
    databaseStructure = new DatabaseStructure(db);
  }
}

相关文章

Context类方法