I am working on sqlite in my android app.
I am doing db.getVersion() to get current version of my database.
it is showing 3 in logcat.
even in constructor i set 4 as a version number.
public Helper(Context context)
{
super(context, DATABASE_NAME, null,4);
}
i am giving 4 it should take 4 as version number.
but its not behaving like this. it is showing 3 as version number.
please any suggestion.
UPDATE:-
public class Helper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "helper.db";
public static final String TITLE = "title";
public static final String AUTHOR = "author";
public static final String ISBN = "isbn";
public Helper(Context context)
{
super(context, DATABASE_NAME, null,4);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL( "CREATE TABLE book1(_id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT, author TEXT,isbn INTEGER);");
Log.v("Create Table", "CREATE TABLE book1(_id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT, author TEXT,isbn INTEGER);");
Log.v("version ", "Version number is "+db.getVersion());
}
You are checking the version number in the onCreate function, why? the OnCreate function should only be called the first time the datbase is created from scratch, in this case it should build the DB as you require fitting to the version you are using.
Can you try checking the DB version after the DB has been created and you ask to get a readable or writable instance of it?
check out the source code of android 4.1.1 SQLiteOpenHelper, here it seems as the db version should be 0 inside the onCreate function, I guess it might be implemented in another way on the version you are testing on.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/database/sqlite/SQLiteOpenHelper.java#242