简体   繁体   中英

Get version database ormlite

I use a database in ormlite. I would like to get the version of my database in the Activity, but I don't know in wich table is saving the version.

Anybody know how can I get the version of the database? I have looked for in the manuals but I haven't found it.

Thanks a lot.

in onCreate write this code

int version = getHelper().getReadableDatabase().getVersion();

hope this help :)

If you are talking about the database version number managed by the Android OS then you will know what the number is because otherwise you will get a call to onUpgrade(...) .

If your onUpgrade(...) method is called, you know what the number is because you get the old version and the new version numbers. If you didn't get the call then you know that the version number you set in your database helper and was passed up to the SQLiteOpenHelper class corresponds to the one in the Android's storage.

Here's a sample of code from a typical ORMLite DatabaseHelper class:

private static final int DATABASE_VERSION = 4;
...

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
}
...

/**
 * This is called when your application is upgraded and it has a higher version 
 * number. This allows you to adjust the various data to match the new version
 * number.
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
    int oldVersion, int newVersion) {
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM