You’re going to need two separate paths:
- The current encrypted database path that you’re going to need to sqlite3_open and key.
- The plain text database path that’s going to be used for sqlcipher_export() for migrating from your encrypted database to plain text.
Currently both of these are are using the same path:
So why don’t we rename this one to be a little clearer:
let encryptedDbPath = String(format: "%@/Documents/encrypted1.sqlite",NSHomeDirectory())
And create another path for the output plain text db
let plaintextDbPath = String(format: "%@/Documents/plaintext1.sqlite",NSHomeDirectory())
Now when opening you’re going to want to use the encrypted db path:
// first open encrypted database
if (sqlite3_open(encryptedDbPath, &db) == SQLITE_OK) {
...
but then when attaching the plaintext db to be exported you’re going to want to use the plain text db path:
let newQuery1 = "ATTACH DATABASE '\(plaintextDbPath)' AS plaintext KEY '';"
Let me know if this resolves the issue for you.
Cheers,
Micah