-
Notifications
You must be signed in to change notification settings - Fork 568
using sqlcipher database across multiple activities? #90
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
Comments
Hi mjguse, You certainly can use SQLCipher for Android across multiple activities. An example of what you can do is make your subclass to |
Hey There - I know you closed this but I may have found a bug. The problem I was having wasn't with the application context at all, it was actually with the name I was using for my database. I was trying to use "FCPokerSun.db" as the name, and for some reason using this particular name creates a non-persisting database with sqlcipher, which does not persist between activities or even between closing/restarting the application. This database name DOES however work properly with just regular sqlite. I tried other 10 character database names with sqlcipher, along with mixing uppercase/lowercase and they all worked... so I'm totally baffled why "FCPokerSun.db" does not and wonder if there are other name combinations that don't... This kept me busy for 6 hours so I don't know if it's a bug but if there's a naming convention for sqlcipher database names that deviates from regular sqlite it may be beneficial to document that somewhere.. anyway thanks for your help. |
Hi mjguse, I tested out your database name on an application I work on which uses SQLCipher for Android, there were no issue using that database name when closing and restarting the application. You might want to verify your application behavior with a debugger to watch exactly what is occurring. Are you properly updating the version of the database when either |
Hey there - Thanks very much for letting me know the problem is on my end. I had used that DB name in past with just regular sqlite and I suppose some remnant must have carried over. Thanks again, have a great day! |
Hey there - I found the problem!! When I initialize sqlcipher and I feed it the same database name: File databaseFile = context.getDatabasePath("pizza.db"); as I feed the constructor for my SQLiteOpenHelper: DatabaseHelper(Context c) { The database then recreates every time that I create a new SQLiteOpenHelper (i.e. closing/restarting the application)... In other words, you need to use separate database names for the initialization function and the SQLiteOpenHelper... I suspect the first database contains keys for encryption... Anyway very sorry to waste your time, I didn't see anything in the documentation that explained this, but glad to finally have it working. |
Hi mjguse, There is nothing wrong with passing the same name of the database to the constructor of the SQLiteOpenHelper subclass, that in fact should stay they same. You should to review what is occurring in your |
Hi there - Really? I have breakpoints in my onCreate method, and if I use the same database for both methods ("pizza.db" as shown below), then everytime that I run the application and create a new DBAdapter in the main activity, the sqliteOpenHelper calls onCreate (which just creates the tables over again, but this means data isn't persisting after the app has been closed)... However - if I use a different database name for sqliteOpenHelper, it totally works as expected... the first time I run the application it creates two databases ("pizza.db" and whatever), encrypts them both, and the next time I run the application onCreate is not called... Do you see anything at quick glance that I'm doing which could be causing this? public class DBAdapter {
} |
Hi mjguse, The issue is that you are calling InitializeSQLCipher inside your constructor, and your InitializeSQLCipher is deleting the database file every time. So every time you create a new DBAdapter it deletes the file. |
aHA!! Thanks a ton! |
Is this possible? I tried using the application context (instead of the activity context) for initializing the database, but regardless of which context I use, everytime that I move onto the second activity my SQLiteOpenHelper creates the tables all over again when it initializes... So the database isn't persisting between activities...
I haven't found anything on Google about using it across activities - does anyone know how this might be achieved?
The text was updated successfully, but these errors were encountered: