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

The following are Jave code examples for showing how to use setVersion() 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: q-mail   File: StoreSchemaDefinition.java   View Source Code Vote up 6 votes
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!");
    }
}
 
Example 2
Project: boohee_v5.6   File: ay.java   View Source Code Vote up 6 votes
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) {
    }
}
 
Example 3
Project: q-mail   File: StoreSchemaDefinition.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 4
Project: q-mail   File: StoreSchemaDefinitionTest.java   View Source Code Vote up 5 votes
@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());
        }
    }
}
 
Example 5
Project: GitHub   File: DbManagerImpl.java   View Source Code Vote up 5 votes
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;
    }
 
Example 6
Project: NightSkyGuide   File: DSObjectDatabaseHelper.java   View Source Code Vote up 5 votes
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();
}
 
Example 7
Project: ifcalc   File: DbHelper.java   View Source Code Vote up 5 votes
@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);
}