fnc12 / sqlite_orm

❤️ SQLite ORM light header only library for modern C++
GNU Affero General Public License v3.0
2.19k stars 305 forks source link

Sqlcipher compatibility #1298

Open DeHby opened 1 month ago

DeHby commented 1 month ago

I have compatibility problems when using sqlcipher with sqlite_orm

image

When dealing with the sqlite3_key problem, I used the on_open method to solve it.

But if I use pragma, it will get an error.

image

The reason for the failure is that the callback of on_open precedes set_pragma.

I hope to add "before" and "after" callbacks for compatibility or other better ways.

trueqbit commented 1 month ago

What's the error you encounter?

DeHby commented 1 month ago

What's the error you encounter?

The call of sqlite3_key is in the callback of on_open, but set_pragma precedes it.

Because the database has been encrypted by SQLCipher, you need to execute sqlite3_key before you can execute set_pragma("journal_mode ").

Otherwise, SQLITE will not be able to decrypt the DB file correctly, recognize the header of SQLite, and prompt the error "file is not a database".

My current solution is to put the on_open function call at the front of the on_open_internal function.