tags:

views:

190

answers:

3

Hi,

In my iphone application,i have used sqlite3 for storing the data. how to get the size of the database using the iphone functionality?

if anybody has any code or any useful link or any other resolution,which would be appreciated.

Thanks,

Mishal Shah

A: 

You can find the database file, of the application in the iPhone simulator, in

~/Library/Application Support/iPhone Simulator/User/Applications/a long number/Documents/

If you have a jail broken phone you can SSH into it and find the applications folder where it will also be in a /Applications//Documents/ folder.

Ross
+1  A: 

Try the following, this could help you

- (NSString *)applicationDocumentsDirectory {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

- (void) logSqlliteStoreSize
{
    NSString *yourSqlLiteFileName = @"YOURDATABASE_NAME.sqlite";
    NSString *yourSqlLitePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: yourSqlLiteFileName];
    NSError *error;
    NSDictionary *storeAttributesOfItemAtPath = [[NSFileManager defaultManager] attributesOfItemAtPath:yourSqlLitePath error:&error];
    // here you should test error, this is a simplified version

    // the next log will show many informations about your sqllite file
    // including the filesize
    NSLog(@"storeAttributesOfItemAtPath=%@", storeAttributesOfItemAtPath);

}
scriba
+1  A: 

You can use the following code (drawn from my answer to this question) to determine both your database's size and the free space on the filesystem:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *persistentStorePath = [documentsDirectory stringByAppendingPathComponent:@"database.sqlite"];

NSError *error = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:persistentStorePath error:&error];
NSLog(@"Persistent store size: %@ bytes", [fileAttributes objectForKey:NSFileSize]);

NSDictionary *fileSystemAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:persistentStorePath error:&error];
NSLog(@"Free space on file system: %@ bytes", [fileSystemAttributes objectForKey:NSFileSystemFreeSize]);

This assumes that your database is called "database.sqlite" and is stored at the root of your application's documents directory.

Brad Larson