Iphone SQLite不向数据库添加项

Iphone SQLite不向数据库添加项,iphone,ios,objective-c,sqlite,Iphone,Ios,Objective C,Sqlite,我有一个SQLite数据库,但当我尝试动态添加项目时,它不起作用 以下是添加脚本: -(void) addPatientToDatabase:(Patient *)newPatient { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]

我有一个SQLite数据库,但当我尝试动态添加项目时,它不起作用

以下是添加脚本:

-(void) addPatientToDatabase:(Patient *)newPatient {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"cities.sqlite"];

    sqlite3 *database;

    if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
        const char *sqlStatement = "insert into patients (firstName, surname, dob, homeNumber, mobileNumber, email, address, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            sqlite3_bind_text(compiledStatement, 1, [newPatient.patientName UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 2, [newPatient.patientSurname UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 3, [newPatient.patientDoB UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 4, [newPatient.patientHomeNumber UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 5, [newPatient.patientMobileNumber UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 6, [newPatient.patientEmail UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(compiledStatement, 7, [newPatient.patientAddress UTF8String], -1, SQLITE_TRANSIENT);
            NSData *dataForPicture = UIImagePNGRepresentation(newPatient.patientPicture);
            sqlite3_bind_blob(compiledStatement, 8, [dataForPicture bytes], [dataForPicture length], SQLITE_TRANSIENT);
        }
        if(sqlite3_step(compiledStatement) == SQLITE_DONE) {
            sqlite3_finalize(compiledStatement);
        }
    }
    sqlite3_close(database);
}
我添加了一些断点,并注意到如果此if语句中存在断点:

if(sqlite3_step(compiledStatement) == SQLITE_DONE) {
那它就不会被捡起来了


提前感谢

当步骤返回SQLITE_DONE以外的任何内容时,请尝试调用:sqlite3_errmsg(数据库)

它将返回指向错误消息()的指针。显示或记录该消息,以找出问题所在