SQLiteDatabase getVersion - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteDatabase getVersion method.

This code example shows how to use the following methods:close, beginTransaction, endTransaction, getVersion, setTransactionSuccessful
                    db = SQLiteDatabase.openOrCreateDatabase(new File(mPath, mName), mFactory);
                else 
                    db = mContext.openOrCreateDatabase(mName, 0, mFactory);
            } 
 
            int version = db.getVersion();
            if (version != mNewVersion) {
                db.beginTransaction();
                try { 
                    if (version == 0) {
                        onCreate(db);
                    } else { 
                        onUpgrade(db, version, mNewVersion);
                    } 
                    db.setVersion(mNewVersion);
                    db.setTransactionSuccessful();
                } finally { 
                    db.endTransaction();
                } 
            } 

8
CodeRank
This code example shows how to use the following methods:execSQL, getVersion, rawQuery
    private boolean isReleased = false;
 
    @Override 
    public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
        Log.v(TAG, "Now we are creating a new database!");
        Log.i(TAG, "Newly created db version: " + database.getVersion());
 
        try { 
            TableUtils.createTable(connectionSource, Card.class);
            TableUtils.createTable(connectionSource, Deck.class);
            TableUtils.createTable(connectionSource, Setting.class);
            TableUtils.createTable(connectionSource, Filter.class);
            TableUtils.createTable(connectionSource, Category.class);
            TableUtils.createTable(connectionSource, LearningData.class);
 
            getSettingDao().create(new Setting()); 
            getCategoryDao().create(new Category()); 
 
            if (database.getVersion() == 0) {
                convertOldDatabase(database);

7
CodeRank
This code example shows how to use the following methods:execSQL, getVersion
				+ KEY_MODIFICATION_DATE + " DATETIME,"
				+ KEY_DUE_DATE + " DATETIME,"
				+ KEY_G_ID + " TEXT,"
				+ KEY_NOTES + " TEXT)";
		 
		db.execSQL(create_tasks_table);
	} 
	 
	private void createCategoriesTable(SQLiteDatabase db) {
		String create_categories_table = "CREATE TABLE " + TABLE_CATEGORIES + "(" 
				+ KEY_ID + " INTEGER PRIMARY KEY,"
				+ KEY_NAME + " TEXT,"
				+ KEY_COLOR + " INTEGER,"
				+ KEY_UPDATED + " DATETIME,"
				+ KEY_G_ID + " TEXT)";
		 
		db.execSQL(create_categories_table);
		 
		// Create first entry of categories table 
		ContentValues values = new ContentValues();

6
CodeRank
This code example shows how to use the following methods:close, getVersion, isOpen, isReadOnly
  
		if (dbExist) {
			if (LOGV) Log.v(TAG, "Found existing DB at " + dbFile);
 
			mDB = SQLiteDatabase.openDatabase(dbFile, null, SQLiteDatabase.OPEN_READONLY);
			int thisDBVersion = mDB.getVersion();
			mDB.close();
			 
			if (LOGV) Log.v(TAG, "Current DB Version: v" + thisDBVersion + " - Shipped DB Version is v" + DATABASE_VERSION);
			if (thisDBVersion != DATABASE_VERSION) {							
				try { 
					copyDB(dbFile);
				} catch (IOException e) {
					throw new Error("Error copying database");
				} 
			}	 
		} 
		else { 
			if (LOGV) Log.v(TAG, "Creating a new DB at " + dbFile);
			// By calling this method and empty database will be created into the default system path 
6
CodeRank
This code example shows how to use the following methods:getVersion
            // Not much we can do to recover at this point 
            Log.e(LOGTAG, "Unable to open or create " + databaseFile);
            return; 
        } 
 
        if (mDatabase.getVersion() != DATABASE_VERSION) {
            mDatabase.beginTransactionNonExclusive();
            try { 
                createTable(); 
                mDatabase.setTransactionSuccessful();
            } finally { 
                mDatabase.endTransaction();
            } 
        } 
    } 
 
    private void createTable() { 
        mDatabase.execSQL("CREATE TABLE " + HTTPAUTH_TABLE_NAME
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
                + HTTPAUTH_HOST_COL + " TEXT, " + HTTPAUTH_REALM_COL
5
CodeRank
This code example shows how to use the following methods:getVersion, setVersion
			 
			if ((file.exists() && file.isDirectory() || file.mkdir()) && file.canWrite()) { 
				try { 
					mDb = SQLiteDatabase.openDatabase(APP_DIR + name, null, SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY); 
					 
					if (mDb.getVersion() == 0) { 
						onCreate(mDb); 
					} else { 
						onUpgrade(mDb, mDb.getVersion(), DATABASE_VERSION); 
					} 
					mDb.setVersion(DATABASE_VERSION); 
					sUseSD = true; 
				} catch (SQLException sqlException) { 
					mDb = new SQLiteOpenHelper(context, name, null, version) { 
						@Override 
						public void onCreate(SQLiteDatabase db) { 
							DatabaseHelper.this.onCreate(db); 
						} 
 
						@Override 
5
CodeRank
This code example shows how to use the following methods:getVersion
 
    /** 
     * Prepare the database for use. 
     */ 
    private void prepareDB() { 
        int version = mDb.getVersion();
 
        // is a new installation 
        if (version < 1) {
            mDb.execSQL(CREATE_TABLE_SETTINGS);
            mDb.setVersion(DATABASE_VERSION);
        } 
    } 
 
    /** 
     * Saves login information on the database. 
     *  
     * @param username 
     *            The user's username 
     * @param apikey 
4
CodeRank
This code example shows how to use the following methods:getVersion
 
    public static int getDBVersion() 
    { 
    	int version = -1;
    	if(mDatabase != null)
    		version = mDatabase.getVersion();
    	return version;
    } 
    public static SurfBIDBHelper getInstance(Context context, int version, int mode)
    { 
    	 
    	if(sqlHelper == null)
    	{ 
    		mInitial = true;
    		mNewVersion = version;
    		sqlHelper = new SurfBIDBHelper(context,databaseName, null, version);
    	} 
    	 
    	 
		if(mode == MODE_READ)
3
CodeRank
This code example shows how to use the following methods:getVersion
	 * @return this (for chaining) 
	 */ 
	public OtokouChargeAdapter open(){ 
		db = dbHelper.getWritableDatabase();
		connectionOpen = true;
		if (db.getVersion() < DB_VERSION) upgradeDB();
		return this;
	} 
	 
	/** 
	 * Since Version 1<p> 
	 *  
	 * Upgrade the database to a new version.<p> 
	 * note: only used when changing database structure, will delete all rows.<br> 
	 * note: need a call to the open() method before a call to this method. 
	 */	 
	private void upgradeDB() { 
		if (connectionOpen) dbHelper.onUpgrade(db, db.getVersion(), DB_VERSION);
	} 
	 

4
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction, execSQL, getVersion
	private final SQLiteStatement myUnsetValueStatement;
	private final SQLiteStatement myDeleteGroupStatement;
 
	public ZLSQLiteConfig(Context context) {
		myDatabase = context.openOrCreateDatabase("config.db", Context.MODE_PRIVATE, null);
		switch (myDatabase.getVersion()) {
			case 0: 
				myDatabase.execSQL("CREATE TABLE config (groupName VARCHAR, name VARCHAR, value VARCHAR, PRIMARY KEY(groupName, name) )");
				break; 
			case 1: 
				myDatabase.beginTransaction();
				SQLiteStatement removeStatement = myDatabase.compileStatement(
					"DELETE FROM config WHERE name = ? AND groupName LIKE ?" 
				); 
				removeStatement.bindString(2, "/%");
				removeStatement.bindString(1, "Size"); removeStatement.execute();
				removeStatement.bindString(1, "Title"); removeStatement.execute();
				removeStatement.bindString(1, "Language"); removeStatement.execute();
				removeStatement.bindString(1, "Encoding"); removeStatement.execute();
				removeStatement.bindString(1, "AuthorSortKey"); removeStatement.execute();

4
CodeRank

Related SQLiteDatabase getVersion Questions & Answers:

getVersion Method Overview
Gets the database version.
See Code Examples for other Android SQLiteDatabase Methods: