iPad 上的 SQLite3 有问题。不断收到错误'constraint failed'



我有一个常见的约束问题。这是我的表创建方案:

创建表"Videos" ("CDate" TEXT NOT NULL, "Name" TEXT NOT NULL,)"Path" TEXT NOT NULL)

这是我的代码:

-(void)insertVideo:(VPVideo*)video
{
    NSString *foo = [NSString stringWithFormat:@"INSERT INTO Videos(CDate,Name,Path) VALUES ('%@', '%@', '%@')",[video.file creationDate],[video.file name],[video.file path]];
    const char *sql = [foo UTF8String];
    printf("%s",sql);
    sqlite3_stmt *statement;
    // Prepare the statement to compile the SQL query into byte-code
    int sqlResult = sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
    if ( sqlResult!= SQLITE_OK) {
        NSAssert1(0,@"Error While creating add statement. '%d'",sqlite3_errmsg(database));
    }
    if(SQLITE_DONE != sqlite3_step(statement))
    {
        NSAssert1(0,@"Error while inserting data. '%s'",sqlite3_errmsg(database));
    }
    else
        sqlite3_finalize(statement);
        //NSLog(@"id of the last insert is : '%lld'",sqlite3_last_insert_rowid(database));
}

调试器点击"插入数据时出错"NSAssert1。报告全文如下:

* assert failure in -[DBAccess insertVideo:],/用户/Vasilis/桌面/项目/IPhone/TestApp/TestApp/DBAccess.m: 157

*由于未捕获的异常而终止应用程序'NSInternalInconsistencyException',原因:'插入时出错'数据。约束失败"

我希望我给了你足够的信息,这样你就能帮助我。我已经尝试了以下方法。
  • 尝试通过绑定插入数据
  • 检查NULL值
  • 改变整个数据库两次(我不知道为什么,但我认为)
  • 正确地尝试插入语句firefox sqlite管理器,似乎工作良好

你认为哪里出了问题?我忘了说"select from"语句在ipad上运行得很好。

修复!问题是Iphone模拟器卡住了,更改的文件没有保存,所以我不得不从模拟器中删除编译后的应用程序,重新添加所有文件,并再次编译清理后的项目。

相关内容

最新更新