Example usage for android.database.sqlite SQLiteDatabase getVersion

List of usage examples for android.database.sqlite SQLiteDatabase getVersion

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase getVersion.

Prototype

public int getVersion() 

Source Link

Document

Gets the database version.

Usage

From source file:info.wncwaterfalls.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    actionBar = getSupportActionBar();/*from  ww w .ja  va2s .  co m*/
    actionBar.setDisplayHomeAsUpEnabled(false);

    mDb = new AttrDatabase(this); // TODO: Make sure this isn't leaky as a sieve

    SharedPreferences appPrefs = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
    int lastKnownDbVersion = appPrefs.getInt(APP_PREF_LAST_KNOWN_DB_VERSION, 0);
    SQLiteDatabase db = mDb.getReadableDatabase();
    int actualDbVersion = db.getVersion();

    // Save actual last version
    if (lastKnownDbVersion != actualDbVersion) {
        SharedPreferences.Editor editor = appPrefs.edit();
        editor.putInt(APP_PREF_LAST_KNOWN_DB_VERSION, actualDbVersion);
        editor.commit();
    }

    // This logic seems to simple to possibly be correct
    if (actualDbVersion > 1 && lastKnownDbVersion < actualDbVersion) {
        // We've been upgraded. Copy shared id's into db for quick searching
        onDatabaseUpgrade();
    }

    // We're done with it.
    mDb.close();

}

From source file:com.contentful.vault.SqliteHelper.java

private boolean isPendingCopy(File dbPath) {
    boolean result = false;
    if (dbPath.exists()) {
        SQLiteDatabase db = context.openOrCreateDatabase(spaceHelper.getDatabaseName(), Context.MODE_PRIVATE,
                null);//from  w w w.j a  v  a 2  s .c  o  m
        try {
            if (spaceHelper.getDatabaseVersion() > db.getVersion()) {
                result = true;
            }
        } finally {
            db.close();
        }
    } else {
        result = true;
    }
    return result;
}

From source file:com.codebutler.farebot.transit.ovc.OVChipDBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = new File(DB_PATH, DB_NAME);
    if (!file.exists()) {
        return false;
    }// www.jav a  2  s. c o m

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating OVChip database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:com.example.ryutasakamoto.readfelica.util.DBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = getDBFile();//from w ww.  j a  v a  2s . c om
    if (!file.exists()) {
        return false;
    }

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating Suica database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:com.codebutler.farebot.card.felica.DBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = new File(DB_PATH, DB_NAME);
    if (!file.exists()) {
        return false;
    }/*from  w  w  w. java2s  . c  o m*/

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (currentVersion != VERSION) {
            Log.d(TAG, String.format("Updating Suica database. Old: %s, new: %s", currentVersion, VERSION));
            tempDatabase.close();
            tempDatabase = null;
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}

From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java

public int getDatabaseMajorVersion() {
    SQLiteDatabase database = this.databaseHelper.getWritableDatabase();
    try {/*from  w w  w .ja v  a  2s  .co  m*/
        return database.getVersion();
    } catch (Exception ex) {
        throw translate(ex);
    } finally {
        close(database);
    }
}

From source file:com.codebutler.farebot.core.DBUtil.java

private boolean hasDatabase() {
    SQLiteDatabase tempDatabase = null;

    File file = getDBFile();//from  w ww.  j  av  a2  s .  co m
    if (!file.exists()) {
        Log.d(TAG, String.format("Database for %s does not exist, will install version %s", getDBName(),
                getDesiredVersion()));
        return false;
    }

    try {
        tempDatabase = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
        int currentVersion = tempDatabase.getVersion();
        if (allowGreaterDatabaseVersions() ? currentVersion < getDesiredVersion()
                : currentVersion != getDesiredVersion()) {
            Log.d(TAG, String.format("Updating %s database. Old: %s, new: %s", getDBName(), currentVersion,
                    getDesiredVersion()));
            tempDatabase.close();
            tempDatabase = null;
        } else {
            Log.d(TAG, String.format("Not updating %s database. Current: %s, app has: %s", getDBName(),
                    currentVersion, getDesiredVersion()));
        }
    } catch (SQLiteException ignored) {
    }

    if (tempDatabase != null) {
        tempDatabase.close();
    }

    return (tempDatabase != null);
}