Reputation: 4479
I would like to check the size of a SQLite database and if it is too big, it will notify the user to stop insert data into it.
But how could I check the total number of rows, or the file size of the database efficiently? It is good to have some O(1) method so that I could check for every insertion the user submitted.
I am working on Qt mainly for Windows.
Upvotes: 1
Views: 1063
Reputation: 90776
You could simply check the size of the database file and associated journal. That would be O(1) since the number of system calls will always be the same. Something like this:
if (QFileInfo(dbFilePath).size() + QFileInfo(dbFilePath + "-journal").size() > maxSize) {
// Prevent insertion
}
Upvotes: 2