I am programatically trying to check the size of SQLite
database stored on the iphone after deleting some rows. The records get deleted, but the file size remains the same. Is there any way I can get the correct size of file after deleting records from sqlite in iOS? Please see the code below:
NSString* databasePath = [[NSString alloc]
initWithString: [self.documentsDirectory stringByAppendingPathComponent: self.databaseFilename]];
unsigned long long fileSize = [[[NSFileManager defaultManager]
attributesOfItemAtPath:databasePath error:nil] fileSize];
Thanks!
I cant use the vaccum approach because it deletes all the records . I am deleting 50% of data only, and not all. So this is not duplicate of this question change sqlite file size after "DELETE FROM table"
The size of a SQLite database file does not necessarily shrink when records are deleted. If auto_vacuum is not enabled, it will never shrink unless you perform a vacuum operation on it.
See https://sqlite.org/lang_vacuum.html and https://sqlite.org/pragma.html#pragma_auto_vacuum .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With