Reputation: 351
I have been successfully using Dbflow for a while now. For the passed month my app has run fine with one sqlCipher database that is loaded with no existing values in its table and second database is a plain sqlite table that is loaded with existing rows in a couple of its tables. With this plain sqlite database I am immediately able to identify that those entries are in the tables they're supposed to be in by looking at the size of the database in the device file explorer as well as querying out the values in code.
My issue is that I needed to move those existing tables from the plain sqlite database to the sqlCipher database. This is when the sqlcipher database stops working the way I expect it to. Now after loading up the databases there is no sign of those entries. It is as if the sqlCipher database(and tables) is being created from scratch based on the ORM's and not actually using the provided existing sqlCipher database.
Here is how I am setting up the functioning plain sqlite Database, and the sqlCipher database that is not working:
Configuration for plain sqlite Database that is working:
The name of the existing database file is 'normalDb.db' and is located in the asset folder
Init Code:
val normalDbConfig = FlowConfig.Builder(this)
.database(
DatabaseConfig.builder(normalDb::class, AndroidSQLiteOpenHelper.createHelperCreator(this))
.databaseName("normalDb")
.build())
.openDatabasesOnInit(true)
.build()
FlowManager.init(normalDbConfig)
Database declaration:
@Database(version = normalDb.VERSION)
abstract class normalDb : DBFlowDatabase(){
companion object {
const val VERSION = 1
}
}
Configuration for SqlCipher Database that does not seem to be loading existing tables:
The name of the existing database file is 'encryptedDb.db' and is located in the asset folder
Init Code:
val encryptedDbConfig = FlowConfig.Builder(this)
.database(
DatabaseConfig.Builder(encryptedDb::class) { db, callback -> SQLCipherHelper(this, db, callback) }
.databaseName("encryptedDb")
.build())
.build()
FlowManager.init(encryptedDbConfig)
Database declaration:
@Database(version = encryptedDb.VERSION)
abstract class encryptedDb : DBFlowDatabase(){
companion object {
const val VERSION = 1
}
}
SqlCipher helper:
class SQLCipherHelper(context: Context,
databaseDefinition: DBFlowDatabase,
callback: DatabaseCallback?)
: SQLCipherOpenHelper(context, databaseDefinition, callback) {
override val cipherSecret get() = "myPassword"
}
Also note that the above code for the encrypted database does compile and run and I can see that it is created on device by looking in the Android file explorer. I am also able to add new entries and then query them, these will also then persist across runs until I delete the on device database files (aka functioning as expected). All that is missing are the initial rows that are in the .db file that I specified as the existing database.
Upvotes: 1
Views: 290
Reputation: 351
The problem turned out to be unrelated to sqlCipher!
The issue turned out to be related to the fact that I was initializing two databases.
By simply initializing the encrypted database with existing values alone the existing values now appeared.
On top of this I was actually able to continue using both databases simply by initializing the encrypted database with existing values first, and then initializing the empty unencrypted database.
Upvotes: 0