0

I have created database and table through sqlite3 using terminal on macbook, then deploy it with my iPhone application. Its working fine in simulator inserting & retrieving the values from table.

But when i install it on real iPhone it is not working, why? I think it can not get the path of database, then how can i do that?

2
  • Just wondering, what platform and tools do you use to develop iphone apps? Commented Apr 15, 2009 at 13:17
  • Question needs a more descriptive title. Commented Apr 15, 2009 at 13:35

1 Answer 1

1

Are you leaving the database in the base app path?
Because if you are, the actual hardware won't allow you to write to files in that directory, just read. To write to the database, you will first have to copy it to an accessible directory.

I'm doing something similar to this (where filename is an NSString containing the name of the database file):

NSArray *docPaths =
  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
NSString *fullName = [docPath stringByAppendingPathComponent:fileName];
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:fullName])
{
  NSString *path = [[NSBundle mainBundle] bundlePath];
  NSString *defaultName = [path stringByAppendingPathComponent:fileName];
  [fm copyItemAtPath:defaultName toPath:fullName error:NULL];
}

Basically, check if the file already exists and copy it from the base bundlePath if it doesn't.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.