Assertion failure error in objective c

后端 未结 2 815
忘了有多久
忘了有多久 2021-01-29 15:16

I have Json datas but I got this error assertion failure when I try to insert this records to sqlite database. I can see the datas with NSLog but I can not insert database. What

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 15:57

    Check out the code below

    if (sqlite3_open([cruddatabase UTF8String], &cruddb)==SQLITE_OK)  {
    
    sqlite3_prepare_v2(cruddatabase, "BEGIN TRANSACTION", -1, &compiledStmt, NULL);
    sqlite3_step(compiledStmt);
    sqlite3_finalize(compiledStmt);
    
    const char *sql = "INSERT INTO LabUpdate (IsSuccess, ProducerId, Latitude, Longitude, Altitude, Slope, SampleDate, PackageNo, Status, Description) VALUES (?,?,?,?,?,?,?,?,?,?)";  
    if(sqlite3_prepare_v2(cruddatabase, sql, -1, &stmt, NULL) == SQLITE_OK){  
    
        sqlite3_prepare_v2(cruddb, sql, 1, &stmt, NULL);
                sqlite3_bind_int(stmt, 1, [str1 integerValue]);
                sqlite3_bind_int(stmt, 2, [str2 integerValue]);
                sqlite3_bind_double(stmt, 3, [str3 floatValue]);
                sqlite3_bind_double(stmt, 4, [str4 floatValue]);
                sqlite3_bind_double(stmt, 5, [str5 floatValue]);
                sqlite3_bind_double(stmt, 6, [str6 floatValue]);
                sqlite3_bind_text(stmt, 7, [str7 UTF8String], -1, SQLITE_TRANSIENT);
                sqlite3_bind_int(stmt, 8, [str8 integerValue]);
                sqlite3_bind_int(stmt, 9, [str9 integerValue]);
                sqlite3_bind_text(stmt, 10, [str10 UTF8String], -1, SQLITE_TRANSIENT);
    
            NSUInteger err = sqlite3_step(compiledStmt);
            if (err != SQLITE_DONE){
                NSLog(@"error while binding %d %s",err, sqlite3_errmsg(database));
            }
            sqlite3_reset(compiledStmt);
        sqlite3_finalize(compiledStmt);     
    } else {
        NSLog(@"Invalid Query");
    }
    
    sqlite3_prepare_v2(cruddatabase, "END TRANSACTION", -1, &compiledStmt, NULL);
    sqlite3_step(compiledStmt);
    sqlite3_finalize(compiledStmt); 
    sqlite3_close(cruddatabase);
    

提交回复
热议问题