Objective-C上的SQLite插入问题(NSInternalInconsistencyException)

Objective-C上的SQLite插入问题(NSInternalInconsistencyException),objective-c,sqlite,insert,Objective C,Sqlite,Insert,错误消息是: 由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“插入时出错” 我已经用SQLiteManager在我的数据库上测试了insert,它工作得很好 这是我的代码: -(void) insertImage:(int) idImage title:(NSString *) title description:(NSString *) desc URL:(

错误消息是:

由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“插入时出错”

我已经用SQLiteManager在我的数据库上测试了insert,它工作得很好

这是我的代码:

-(void) insertImage:(int) idImage
              title:(NSString *) title 
        description:(NSString *) desc 
                URL:(NSString *) URL 
           ImageURL:(NSString *) imageURL 
               date:(NSString *) date{

    char *errorMsg;
    sqlite3 *database;

    if (sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK) {

        NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO tb_test VALUES( \'?\', \'?\', \'?\', \'?\', \'?\', \'?\');"];
        sqlite3_stmt *stmt;

        sqlite3_exec(database, "BEGIN", 0, 0, 0);

        if (sqlite3_prepare_v2(database, [insertSQL UTF8String], -1, &stmt, nil) == SQLITE_OK) {

            sqlite3_bind_int(stmt, 1, idImage);
            sqlite3_bind_text(stmt, 2, [title UTF8String], -1, NULL);
            sqlite3_bind_text(stmt, 3, [desc UTF8String], -1, NULL);
            sqlite3_bind_text(stmt, 4, [URL UTF8String], -1, NULL);
            sqlite3_bind_text(stmt, 5, [iamgeURL UTF8String], -1, NULL);
            sqlite3_bind_text(stmt, 6, [date UTF8String], -1, NULL);
        }


//        NSLog(@"sqlite3_step(stmt) = %d", sqlite3_step(stmt));

        if (sqlite3_step(stmt) != SQLITE_DONE) {
           NSAssert1(0, @"Error on insert", errorMsg);
        }

        sqlite3_finalize(stmt);

        sqlite3_exec(database, "COMMIT", 0, 0, 0);
        sqlite3_close(database);

    }
}
有人能帮我吗


提前谢谢

我不是100%,但我认为您不应该在代币周围放置
。因此,您可能希望尝试这种方法

NSString *insertSQL = @"INSERT INTO tb_test VALUES(?, ?, ?, ?, ?, ?);";

当您绑定(例如,
sqlite3\u bind\u text)时,SQLite会执行所需的适当转义/引用。

为什么要手动编写SQL?浪费时间。至少使用FMDB。一个更好的解决方案是直接使用核心数据(这也会让你在未来更好地集成iCloud)。我之所以使用它,是因为这是我的第一个应用程序,在我开始编程之前,我对核心数据一无所知……顺便说一句,这是一个几乎与android完全相同的应用程序,在这里,我也使用了SQLite。可移植性是直接使用SQLite的一个原因,但是,即使这样,iCloud集成可能会驱动您访问核心数据。不…这不是错误…我仍然无法在我的数据库中插入任何语句。。。