当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.setVersion方法代码示例

本文整理汇总了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!");
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:26,代码来源:StoreSchemaDefinition.java

示例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) {
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:ay.java

示例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);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:15,代码来源:StoreSchemaDefinition.java

示例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());
        }
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:15,代码来源:StoreSchemaDefinitionTest.java

示例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;
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:DbManagerImpl.java

示例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();
}
 
开发者ID:MTBehnke,项目名称:NightSkyGuide,代码行数:9,代码来源:DSObjectDatabaseHelper.java

示例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);
}
 
开发者ID:caiovidaln,项目名称:ifcalc,代码行数:34,代码来源:DbHelper.java


注:本文中的android.database.sqlite.SQLiteDatabase.setVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。