Wenn ich die Verbindung mit der Datenbank zu öffnen, sagt Konsole: "Fehler beim Öffnen !: 14". Ich habe "mybase.sqlite" in den Ordner Ressourcen meines Projekts eingefügt und verwende das FMDB-Framework.Fehler für die offene Verbindung der Datenbank mit FMDB
Für offene verbinde ich diesen Code bin mit:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FMDatabase* db = [FMDatabase databaseWithPath:@"/mybase.sqlite"];
if (![db open]) {
NSLog(@"Não abriu o banco de dados.");
[pool release];
return 0;
}
In AppDelegate ich diesen Code enthalten:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
// Override point for customization after application launch. HomeViewController *homeVC = [[HomeViewController alloc] init]; navigationController = [[UINavigationController alloc] initWithRootViewController:homeVC]; [self createEditableCopyOfDatabaseIfNeeded]; [window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES; }
- (void)createEditableCopyOfDatabaseIfNeeded{ BOOL success; NSFileManager
*fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString
*documentsDirectory = [paths objectAtIndex:0]; NSString
*writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"mybase.sqlite"]; success = [fileManager fileExistsAtPath:writableDBPath]; NSLog(@"Success %d", success); if (success) return; NSString
*defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mybase.sqlite"]; success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error]; if (!success) { NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]); } }
Lucas sollten Sie die Antwort als akzeptiert markieren, wie es Ihre Frage beantwortet. –
@LucasMoreria Dies wurde immer noch nicht akzeptiert? Es ist eine perfekte Antwort. – MackieeE
@ Slycel's Antwort ist perfekt und es funktioniert. Sie sollten die Antwort als akzeptiert markieren. –