本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.setVersion方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.setVersion方法的具体用法?Java SQLiteDatabase.setVersion怎么用?Java SQLiteDatabase.setVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.setVersion方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: cg
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void cg() {
try {
File file = new File(I);
File file2 = new File(this.iB);
if (!file.exists()) {
file.mkdirs();
}
if (!file2.exists()) {
file2.createNewFile();
}
if (file2.exists()) {
SQLiteDatabase openOrCreateDatabase = SQLiteDatabase.openOrCreateDatabase(file2, null);
openOrCreateDatabase.execSQL("CREATE TABLE IF NOT EXISTS bdcltb09(id CHAR(40) PRIMARY KEY,time DOUBLE,tag DOUBLE, type DOUBLE , ac INT);");
openOrCreateDatabase.execSQL("CREATE TABLE IF NOT EXISTS wof(id CHAR(15) PRIMARY KEY,mktime DOUBLE,time DOUBLE, ac INT, bc INT, cc INT);");
openOrCreateDatabase.setVersion(1);
openOrCreateDatabase.close();
}
} catch (Exception e) {
}
}
示例3: doDbUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void doDbUpgrade(final SQLiteDatabase db) {
try {
upgradeDatabase(db);
} catch (Exception e) {
if (BuildConfig.DEBUG) {
throw new Error("Exception while upgrading database", e);
}
Timber.e(e, "Exception while upgrading database. Resetting the DB to v0");
db.setVersion(0);
upgradeDatabase(db);
}
}
示例4: doDbUpgrade_withBadDatabase_shouldThrowInDebugBuild
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Test
public void doDbUpgrade_withBadDatabase_shouldThrowInDebugBuild() {
if (BuildConfig.DEBUG) {
SQLiteDatabase database = SQLiteDatabase.create(null);
database.setVersion(29);
try {
storeSchemaDefinition.doDbUpgrade(database);
fail("Expected Error");
} catch (Error e) {
assertEquals("Exception while upgrading database", e.getMessage());
}
}
}
示例5: 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;
}
示例6: forceDatabaseReload
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void forceDatabaseReload(Context context) {
DSObjectDatabaseHelper dbHelper = new DSObjectDatabaseHelper(context);
dbHelper.setForcedUpgrade(DATABASE_VERSION);
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.setVersion(-1);
db.close();
dbHelper.getWritableDatabase();
}
示例7: onUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onUpgrade(SQLiteDatabase dataBase, int oldVersion, int newVersion) {
try {
if(oldVersion < 4) {
dataBase.execSQL("ALTER TABLE lista RENAME TO " + DISCIPLINA);
dataBase.execSQL("ALTER TABLE " + DISCIPLINA + " ADD COLUMN " + ID_SUAP + " TEXT NOT NULL;");
} else if(oldVersion == 4) {
dataBase.execSQL("CREATE TABLE IF NOT EXISTS " + DISCIPLINA + " (_id INTEGER PRIMARY KEY AUTOINCREMENT," +
TITULO + " TEXT NOT NULL, " + NOTAB1 + " NUMBER NOT NULL, " + NOTAB2 + " NUMBER NOT NULL, "
+ NOTAB3 + " NUMBER NOT NULL, " + NOTAB4 + " NUMBER NOT NULL, " + PROVA_FINAL + " NUMBER NOT NULL, "
+ MEDIA + " NUMBER NOT NULL, " + SITUACAO + " TEXT NOT NULL, " + TIPO_DISCI + " TEXT NOT NULL);");
dataBase.execSQL("CREATE TABLE IF NOT EXISTS " + ANOTACAO + " (_id INTEGER PRIMARY KEY AUTOINCREMENT," +
TITULO_ANOTACAO + " TEXT NOT NULL, " + CORPO + " TEXT NOT NULL, " + DATETIME + " TEXT NOT NULL);");
dataBase.execSQL("INSERT INTO " + DISCIPLINA + " SELECT " + TITULO + ", " +
NOTAB1 + ", " + NOTAB2 + ", " + NOTAB3 + ", " +
NOTAB4 + ", " + PROVA_FINAL + ", " + MEDIA + ", " + SITUACAO + ", " +
TIPO_DISCI + " FROM disciplinasnew;");
dataBase.execSQL("DROP TABLE IF EXISTS disciplinasnew;");
dataBase.execSQL("ALTER TABLE " + DISCIPLINA + " ADD COLUMN " + ID_SUAP + " TEXT NOT NULL;");
}
} catch (Exception e) {
dataBase.execSQL("DROP TABLE IF EXISTS lista;");
dataBase.execSQL("DROP TABLE IF EXISTS disciplinasnew;");
dataBase.execSQL("DROP TABLE IF EXISTS " + DISCIPLINA + ";");
dataBase.execSQL("DROP TABLE IF EXISTS " + ANOTACAO + ";");
createTables(dataBase);
}
dataBase.setVersion(newVersion);
}