Iphone 即使没有错误,也无法添加到sqlite数据库

Iphone 即使没有错误,也无法添加到sqlite数据库,iphone,database,xcode,sqlite,Iphone,Database,Xcode,Sqlite,我正在为学校的最后一个项目制作一个iphone应用程序,我遇到了一些麻烦。我将它连接到一个sqlite数据库,但即使我在xcode中没有发现任何错误,并且当我使用调试器遍历代码时,它表明它正在工作,但实际上它没有更新。我在网上看到其他几个线程也有类似的问题,但我无法通过查看它们来解决问题。以下是相关代码,但如果您认为需要了解更多信息,我很乐意将其全部发布: 首先调用createAndCheckCode方法,然后调用addRecipe方法。我只是在一个普通的字符串中输入,直到我能找出如何使它工作。

我正在为学校的最后一个项目制作一个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);


 }

编辑/删除邮件

为什么要注释掉您的邮件?这有点重要。检查模拟器存储其文件的文件夹,并再次检查DB文件是否在其中。您计算机上的路径如下所示:/Users//Library/Application Support/iPhone Simulator/5.0/Applications//Documents/mu太短了:我刚刚将其注释掉,因为它所做的只是发送一条错误消息。我把它放回去了,但没什么区别。调试程序时,程序从未出现错误。贝克:我检查了一下,数据库文件就在那里。我花了一段时间才找到它,因为我花了一段时间才意识到mac电脑一定有像PC一样的隐藏文件夹!(我对他们完全陌生)。