2013-03-15 4 views
0

Прежде всего, Извините. Я не очень хорошо владею английским языком. Здравствуй. Я начинаю iOS.Отношение основных данных с предварительно заполненным sqlite

В настоящее время я развивается так:

  1. удалить автоматически генерируемый ядро ​​SQLite данные файла
  2. скопировать мой созданный SQLite файл удален путь к файлу SQLite с помощью FireFox менеджера SQLite
    (SQLite с помощью Z_PK, Z_ENT, Z_OPT)

Два вопроса:

  1. Как с reate entity отношения с использованием firefox sqlite manager.
  2. Как предварительно создать в случае подробных параметров данных ядра, таких как правило удаления отношений, свойство атрибута в менеджере sqlite или что-то еще.

ответ

0

Ну, в основном вам нужно получить пустую базу данных, созданную вашим проектом, используя вашу схему, а затем манипулировать ею, чтобы хранить нужные данные. Больше информации here

Альтернативный метод, который не описан в ссылке, копирует данные из вашей базы данных в базу данных Core Data с использованием самих основных данных (и библиотеки SQLite для чтения другой базы данных).

+0

Это sqlite Индексный запрос = выражения отношения сущности данных ядра? – user1987329

+0

Да, отношения «один-к-одному» просто указывают на идентификатор соответствующего объекта в другой таблице. Я не уверен, что один-ко-многим. – borrrden

0
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 
if (_persistentStoreCoordinator != nil) { 
    return _persistentStoreCoordinator; 
} 

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataBooks.CDBStore"]; 

/* 
Set up the store. 
For the sake of illustration, provide a pre-populated default store. 
*/ 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
// If the expected store doesn’t exist, copy the default store. 
if (![fileManager fileExistsAtPath:[storeURL path]]) { 
    NSURL *defaultStoreURL = [[NSBundle mainBundle] URLForResource:@"CoreDataBooks" withExtension:@"CDBStore"]; 
    if (defaultStoreURL) { 
     [fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:NULL]; 
    } 
} 

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; 
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; 

NSError *error; 
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { 
    /* 
    Replace this implementation with code to handle the error appropriately. 

    abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

    Typical reasons for an error here include: 
    * The persistent store is not accessible; 
    * The schema for the persistent store is incompatible with current managed object model. 
    Check the error message to determine what the actual problem was. 


    If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory. 

    If you encounter schema incompatibility errors during development, you can reduce their frequency by: 
    * Simply deleting the existing store: 
    [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil] 

    * Performing automatic lightweight migration by passing the following dictionary as the options parameter: 
    @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} 

    Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details. 

    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

return _persistentStoreCoordinator; 

Код взят из Apple, Docs Основные данные книги Link Вы должны иметь предварительно заполненные БД данных, которая была заселена с помощью основных данных. Эта функция копирует предварительно заполненную базу данных в основное хранилище хранилища БД при первом запуске приложения.


Смежные вопросы