Я делаю приложение для iPhone для финального проекта в школе, и у меня возникли некоторые проблемы.Я подключил его к базе данных sqlite, но, несмотря на то, что я не получаю никаких ошибок в xcode, и когда я прошел через код с помощью отладчика, это указывает на то, что он работает, но фактически не обновляется.Я видел несколько других тем с аналогичными проблемами в сети, но я не смог решить проблему, посмотрев на них.Вот соответствующий код, но если вы считаете, что вам нужно больше узнать, я буду рад опубликовать все это: сначала вызывается метод createAndCheckCode, а затем метод addRecipe.Я просто в общей строке, пока я не могу понять, как заставить его работать.я могу просматривать содержимое базы данных из другой программы.
(void) addToDatabase
{
databaseName = @"recipeappdatabase.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Check if the SQL database has already been
//saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists then return without doing anything
if(!success)
{
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
}
// Setup the database object
sqlite3 *database;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "insert into Recipes (title) VALUES ('toor')";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 1, sqlStatement, -1, SQLITE_TRANSIENT);
}
//if (sqlite3_step(compiledStatement) != SQLITE_DONE)
//NSAssert1(0, @"Error updating table: %s", errorMsg);
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
Редактировать / Удалить сообщение