How to Reduce Your SQLite Database File Size Using Qt

Below is what I do for clearing and compressing my SQLite database files in Qt. Usually when you delete some entries from a SQLite database, it does not get deleted physically but instead it just gets marked as deleted and is not retrieved in queries. The good thing about this is that it works fast. But the obvious downside is the fact that the free space is not released. To release the space occupied by deleted files you need to do the following:

QSqlQuery query(db);

query.prepare("VACUUM");
if (!query.exec())
{
	QMessageBox::critical(this, "Error", "Can't compress database.");
}

Note that db is your QSqlDatabase and VACUUM is the SQLite command responsible for compressing the database.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.