SQLCipher. Database becomes malformed if set key in transaction

47 views
Skip to first unread message

Vladislav Schegolev

unread,
Jun 4, 2018, 11:39:42 AM6/4/18
to FMDB
https://discuss.zetetic.net/t/database-becomes-malformed-if-set-key-in-transaction/2889

Hi.

I caught the issue on Mac that a database sometimes becomes malformed. After spending hours of debugging to understand the problem I noticed that key is set after the transaction is initiated to perform table updates. After moving sqlite3_key after begin exclusive transaction the issue is gone.

Could this really be the reason?

Objective-C FMDB wrapper around SQLite is used.

Works fine.

[dbQueue inDatabase:^(FMDatabase *db) {
	[db setKeySafe:[DBManager getPragmaKey]];

	[db beginTransaction];
	...
];

The reason is that a database becomes malformed.

[dbQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
	[db setKeySafe:[DBManager getPragmaKey]];
	...
];
Reply all
Reply to author
Forward
0 new messages