Reputation: 59
I have a local database and it can store n number of data's. I have to restrict the db limit to a maximum of 2 Mb. How it is possible? Please help me
Upvotes: 2
Views: 229
Reputation: 75788
You can use getPath().length()
SQLiteDatabase _SQLITE_obj= getWritableDatabase();
long dbSIZE= new File(_SQLITE_obj.getPath()).length(); // Get Length
long dbSIZE_KB= dbSIZE/ 1024; //Convert to KB
long dbSIZE_MB= dbSIZE_KB/ 1024; // KB to MB
Now
if (dbSIZE_MB> 2)
{
// Your logic
}
Upvotes: 1
Reputation: 180080
You can use PRAGMA max_page_count to restrict the size of the database file (this depends on the page size).
Upvotes: 1