Skip to content

SQLiteOpenHelper not calling onUpgrade #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Alexander-Campbell opened this issue Jun 20, 2012 · 5 comments
Closed

SQLiteOpenHelper not calling onUpgrade #59

Alexander-Campbell opened this issue Jun 20, 2012 · 5 comments

Comments

@Alexander-Campbell
Copy link

Hello,
I have upgraded my version of SQLCipher from 1.1.0 to 2.0.8, in order to get this to work I require to call upgradeDatabaseFormatFromVersion1To2 on the 1.1.0 DBs. How I have tried to implement this is to increase the DB version and then in the onUpgrade function call the upgradeDatabaseFormatFromVersion1To2 function.

The problem I am having is the onUpgrade function is not being called when I create my SQLiteOpenHelper class. I have check the versions of the DB using getVersion(), they are correct. I have also manually called the upgradeDatabaseFormatFromVersion1To2 function on a 1.1 DB and when I import the DB it works fine.

Any ideas why the onUpgrade is not firing, I thought of function template changes, or maybe the order in which I am calling these functions.

@developernotes
Copy link
Member

Hi Alexander-Campbell,

There are two things you should check, first verify that you are passing the new version number to the constructor of SQLiteOpenHelper. Note that it won't call the onUpgrade function until a request for either getReadableDatabase() or getWritableDatabase() is made. You will want to look into where you call either of those methods within your application. We also have a test that verifies this here.

@Alexander-Campbell
Copy link
Author

Hello,
So in fact the events are firing correctly. What I think is raising the exception is trying to open the DB (with Cipher1.0.1) with the 2.0.8 libararies. This will happen before trying to call the upgradeDatabaseFormatFromVersion1To2 from the onUpgrade function in the SQLiteOpenHelper class.

What I have done is call the getWritableDatabase function if this throws an exception, then I call upgradeDatabaseFormatFromVersion1To2 and call again getWritableDatabase, this works but is not the ideal solution.

Is there any way to detect the SQLCipher version on a DB before calling the getReadable/WriteableDatabase ? That way I can know more exactly when to call the upgrade procedure.

thanks

@developernotes
Copy link
Member

Hi Alexander-Campbell,

A read request would throw a SQLiteException - something like select count(*) from sqlite_master; should suffice. You could then trap the exception and handle your upgrade process.

@BharathiKasi
Copy link

hi all actually when you change the database version on
public className extends sqliteOnHelper{

className(Context context){
super(context, // your database name-- DATABASE_NAME, // you cursorFactory -- null, you current version -- 2);
}
}
so the version is match with older version then it won't invoke the method called
onUpgrade (SQLitedatase,int olderversion ,int newVersion)
if suppose you enter the new version then it wil invoke the onUpgrade method.
i am newer to android as of my knowledge i post this .
Thank you.

@developernotes
Copy link
Member

Hi @BharathiKasi

Yes, increasing the version number supplied to the constructor argument of the SQLiteOpenHelper will trigger onUpgrade when requesting the database. If you have any further questions related to SQLCipher, please feel free to post them in our Community Discuss site here. Thanks!

@sqlcipher sqlcipher locked and limited conversation to collaborators Aug 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants