本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.getVersion方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.getVersion方法的具体用法?Java SQLiteDatabase.getVersion怎么用?Java SQLiteDatabase.getVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.getVersion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upgradeDatabase
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void upgradeDatabase(final SQLiteDatabase db) {
Timber.i("Upgrading database from version %d to version %d", db.getVersion(), DB_VERSION);
db.beginTransaction();
try {
// schema version 29 was when we moved to incremental updates
// in the case of a new db or a < v29 db, we blow away and start from scratch
if (db.getVersion() < 29) {
dbCreateDatabaseFromScratch(db);
} else {
RealMigrationsHelper migrationsHelper = new RealMigrationsHelper(localStore);
Migrations.upgradeDatabase(db, migrationsHelper);
}
db.setVersion(LocalStore.DB_VERSION);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (db.getVersion() != LocalStore.DB_VERSION) {
throw new RuntimeException("Database upgrade failed!");
}
}
示例2: getReadableDatabase
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Create and/or open a database. This will be the same object returned by
* {@link #getWritableDatabase} unless some problem, such as a full disk,
* requires the database to be opened read-only. In that case, a read-only
* database object will be returned. If the problem is fixed, a future call
* to {@link #getWritableDatabase} may succeed, in which case the read-only
* database object will be closed and the read/write object will be returned
* in the future.
*
* <p class="caution">Like {@link #getWritableDatabase}, this method may
* take a long time to return, so you should not call it from the
* application main thread, including from
* {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
*
* @return a database object valid until {@link #getWritableDatabase}
* or {@link #close} is called.
* @throws SQLiteException if the database cannot be opened
*/
@Override
public synchronized SQLiteDatabase 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) {
if (mName == null) throw e; // Can't open a temp database read-only!
Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
}
SQLiteDatabase db = null;
try {
mIsInitializing = true;
String path = mContext.getDatabasePath(mName).getPath();
db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY);
if (db.getVersion() != mNewVersion) {
throw new SQLiteException("Can't upgrade read-only database from version " +
db.getVersion() + " to " + mNewVersion + ": " + path);
}
onOpen(db);
Log.w(TAG, "Opened " + mName + " in read-only mode");
mDatabase = db;
return mDatabase;
} finally {
mIsInitializing = false;
if (db != null && db != mDatabase) db.close();
}
}
示例3: getInstance
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public synchronized static DbManager getInstance(DaoConfig daoConfig) {
if (daoConfig == null) {//使用默认配置
daoConfig = new DaoConfig();
}
DbManagerImpl dao = DAO_MAP.get(daoConfig);
if (dao == null) {
dao = new DbManagerImpl(daoConfig);
DAO_MAP.put(daoConfig, dao);
} else {
dao.daoConfig = daoConfig;
}
// update the database if needed
SQLiteDatabase database = dao.database;
int oldVersion = database.getVersion();
int newVersion = daoConfig.getDbVersion();
if (oldVersion != newVersion) {
if (oldVersion != 0) {
DbUpgradeListener upgradeListener = daoConfig.getDbUpgradeListener();
if (upgradeListener != null) {
upgradeListener.onUpgrade(dao, oldVersion, newVersion);
} else {
try {
dao.dropDb();
} catch (DbException e) {
LogUtil.e(e.getMessage(), e);
}
}
}
database.setVersion(newVersion);
}
return dao;
}
示例4: upgradeDatabase
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@SuppressWarnings("fallthrough")
public static void upgradeDatabase(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
switch (db.getVersion()) {
case 29:
MigrationTo30.addDeletedColumn(db);
case 30:
MigrationTo31.changeMsgFolderIdDeletedDateIndex(db);
case 31:
MigrationTo32.updateDeletedColumnFromFlags(db);
case 32:
MigrationTo33.addPreviewColumn(db);
case 33:
MigrationTo34.addFlaggedCountColumn(db);
case 34:
MigrationTo35.updateRemoveXNoSeenInfoFlag(db);
case 35:
MigrationTo36.addAttachmentsContentIdColumn(db);
case 36:
MigrationTo37.addAttachmentsContentDispositionColumn(db);
case 37:
// Database version 38 is solely to prune cached attachments now that we clear them better
case 38:
MigrationTo39.headersPruneOrphans(db);
case 39:
MigrationTo40.addMimeTypeColumn(db);
case 40:
MigrationTo41.db41FoldersAddClassColumns(db);
MigrationTo41.db41UpdateFolderMetadata(db, migrationsHelper);
case 41:
boolean notUpdatingFromEarlierThan41 = db.getVersion() == 41;
if (notUpdatingFromEarlierThan41) {
MigrationTo42.from41MoveFolderPreferences(migrationsHelper);
}
case 42:
MigrationTo43.fixOutboxFolders(db, migrationsHelper);
case 43:
MigrationTo44.addMessagesThreadingColumns(db);
case 44:
MigrationTo45.changeThreadingIndexes(db);
case 45:
MigrationTo46.addMessagesFlagColumns(db, migrationsHelper);
case 46:
MigrationTo47.createThreadsTable(db);
case 47:
MigrationTo48.updateThreadsSetRootWhereNull(db);
case 48:
MigrationTo49.createMsgCompositeIndex(db);
case 49:
MigrationTo50.foldersAddNotifyClassColumn(db, migrationsHelper);
case 50:
MigrationTo51.db51MigrateMessageFormat(db, migrationsHelper);
case 51:
MigrationTo52.addMoreMessagesColumnToFoldersTable(db);
case 52:
MigrationTo53.removeNullValuesFromEmptyColumnInMessagesTable(db);
case 53:
MigrationTo54.addPreviewTypeColumn(db);
case 54:
MigrationTo55.createFtsSearchTable(db, migrationsHelper);
case 55:
MigrationTo56.cleanUpFtsTable(db);
case 56:
MigrationTo57.fixDataLocationForMultipartParts(db);
case 57:
MigrationTo58.cleanUpOrphanedData(db);
MigrationTo58.createDeleteMessageTrigger(db);
case 58:
MigrationTo59.addMissingIndexes(db);
case 59:
MigrationTo60.migratePendingCommands(db);
case 60:
MigrationTo61.addFolderRemoteId(db);
case 61:
MigrationTo62.addFolderParentRemoteId(db);
case 63:
MigrationTo63.removeErrorsFolder(db);
}
}