没有这样的表错误

Sun*_*nny 16 sqlite xcode4

我不得不搜索关于这些错误的很多帖子,但我仍然无法解决问题.这是我的代码,谁能帮助我看看出了什么问题?

- (void) copyDatabaseIfNeeded {


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SQL.sqlite"];

    if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) 
    {
        NSLog(@"Database opened successfully");

if(updateStmt == nil) {
            NSString *updStmt = [NSString stringWithFormat: @"UPDATE Coffee SET CoffeeName = '500 Plus', Price = '1.40' Where CoffeeID= '3'"];
   const char *mupdate_stmt = [updStmt UTF8String]; 

if(sqlite3_prepare_v2(newDBconnection, mupdate_stmt, -1, &updateStmt, NULL) != SQLITE_OK){
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(newDBconnection));
            } else {
                NSLog(@"Update successful");
            }

        }
        if(SQLITE_DONE != sqlite3_step(updateStmt))
            NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(newDBconnection));
        else {
            sqlite3_reset(updateStmt);
            NSLog(@"Step successful");

        }
    } 
    else 
    {
        NSLog(@"Error in opening database  ");
    }
}
Run Code Online (Sandbox Code Playgroud)

ham*_*ene 32

没有表CoffeeSQL.sqlite.

如果数据库文件不存在,SQLite将自动创建数据库文件.所以如果你path错了,你打开一个空的数据库文件,当然不包含任何表.确保数据库文件存在,并且它不为空.

您可以通过运行SELECT * FROM sqlite_master;查询来查看数据库中的表.